DEV Community

Discussion on: Mongodb-native over mongoose?

Collapse
helenasometimes profile image
Nienke • Edited on

So my first reaction to your question was "huh, why would you not want to use Mongoose?" I am using Mongoose because it was recommended to me, and I never really looked into using MongoDB without it.

But then I looked at the MongoDB docs, and you are on to something! Compare the queries below:

Using Mongoose:

Book.find({ 'released_in_year': 2017 }, 'title author')
Enter fullscreen mode Exit fullscreen mode

Using pure Mongo:

db.book.find({released_in_year:{'2017'}}, {title: true, author: true})
Enter fullscreen mode Exit fullscreen mode

I'd say they're both pretty readable. What I think is the answer to "should I use Mongoose or not" really depends on the app you're building. For simpler apps you don't need the extra abstraction layer that Mongoose adds. For more complex apps with complicated querying, using Mongoose probably makes your life a bit easier.

Collapse
tojacob profile image
Jacob Samuel G. Author

It's true, it depends on the application.

Personally I have decided not to use mongoose in projects where 80% of its extra features will not be used (schema, virtuals, pupulate, hooks, etc.).

And although it is not "so" important, the native driver is faster! The only thing is that we must manually configure the connection pool, although it is not difficult.