Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

How is mongoose built on top of mongodb?


Asked by Aydin Montgomery on Dec 08, 2021 MongoDB



Mongoose is built on top of the official MongoDB Node.js driver. Each mongoose model keeps a reference to a native MongoDB driver collection. The collection object can be accessed using YourModel.collection. However, using the collection object directly bypasses all mongoose features, including hooks, validation, etc.
One may also ask,
Mongoose is an object document modeling (ODM) layer that sits on top of Node's MongoDB driver. If your coming from SQL, it's similar to an ORM for a relational database. While it's not required to use Mongoose with the Mongo, here are four reasons why using Mongoose with MongoDB is generally a good idea.
Thereof, Mongoose is a MongoDB object modeling tool designed to work in an asynchronous environment. Mongoose supports both promises and callbacks.
Consequently,
In terms of Node.js, mongodb is the native driver for interacting with a mongodb instance and mongoose is an Object modeling tool for MongoDB. Mongoose is built on top of the MongoDB driver to provide programmers with a way to model their data. Mongoose vs. the MongoDB Node Driver | by Alexander Karan ...
In this manner,
One more difference I found with respect to both is that it is fairly easy to connect to multiple databases with mongodb native driver while you have to use work arounds in mongoose which still have some drawbacks. So if you wanna go for a multitenant application, go for mongodb native driver.