Tell us what’s happening:
Hi,
I tried to compete this project using MongoDB, everything was perfect until the functional tests. I couldn’t manage to pass functional tests on my work, those tests didn’t hit the routes in api.js. I gave up and I finished this project using mongoose instead of MongoDB.
Anyone have completed this project using MongoDB, may share her/his/their work so that I can see how it works? I’m only interested in the functional_tests test(the last test), I’ve already passed all the other challenges. Also, I share my own code(100% complete), in case you like to change my code, remove mongoose and implement MongoDB:
(Again I’m telling my code does passes all the test 100%, i just want to learn how to make it work using MongoDB instead of mongoose)
The QA course teaches us to use mongoose, presumably because it’s considerably easier and more code-efficient than using the MongoDB API for small projects like this. I completed all of the QA projects this way. With larger and/or more complex datasets, there are arguments for using MongoDB, in terms of performance and avoiding errors, but why not use mongoose in this instance?
I’m not favoring one against the other. I just would like to learn how to implement the other one, or if it’s possible to implement MongoDB in this project.
Absolutely, I get that. I’m sure it is possible to use mongodb for these projects, but I’ll leave it to anyone else who might have attempted to do so to explain how they managed it.
Mongoose is just an ODM for MongoDB. You are by definition using MongoDB if you use Mongoose.
You do not have to use Mongoose with the project. Here is a version without Mongoose.
I pretty much just yoinked the demo project code and removed Mongoose. I always use some sort of ORM/ODM, so it took a bit of docs diving and I’m sure the code isn’t great.
Hi,
I like your code, thank you for sharing it. It works like charm.
When I used MongoDB on this project, I copied the approach we had use in the course “Advanced Node”.
Also changed api.js file corresponding code from
module.exports = function(app) {…}
into
function(app, myDataBase) {…}
Maybe those changes had ruined the way how the test runner works, and the functional tests failed. Actually, I like the way you use MongoDB(without writing code like myDB(async client => {…})). I don’t understand why would we implement it in that fashion in the course “Advanced Node”. Your way is more simplistic and it stays a bit discrete from the rest of the code, instead of enclosing the other routing codes. Next time I will implement your way.
Cheers.