Reputation: 1433
We are in the process of writing tests for our Node/MongoDB backend and I have a question about finding documents.
My understanding is it's preferable to use Mongoose to get your documents as opposed to the MongoDB driver. In other words, doing Customer.findOne().exec()
instead of setting up a db connection and then doing db.collection("customers").findOne()
.
Other than the first option (using Mongoose to find the doc) being slightly less verbose, I'm curious what the other reasons are. Is a straight MongoDB lookup a bigger drag on the database?
Upvotes: 0
Views: 101
Reputation: 2401
One of the great feature of mongoose is the built in validation mechanism. Also the Populate method to get data from multiple collections is an awesome characteristic of Mongoose. In terms of query performance, here is a good read:
https://medium.com/@bugwheels94/performance-difference-in-mongoose-vs-mongodb-60be831c69ad
Hope this helps :)
Upvotes: 1