Rahmat Hidayat
Rahmat Hidayat

Reputation: 87

What are difference of mongoose and mongoJS ? Which should I use?

I just want to know, what are differences of mongoose and mongoJS. And, what the advantage and the lack if we use mongoose or mongoJS ? Because we know that are many depedency that use to connecting NodeJS and MongoDB. For example mongoose and mongoJS.

Upvotes: 2

Views: 1791

Answers (3)

Vishal Chimnani
Vishal Chimnani

Reputation: 11

Mongoose is higher level interface to Mongodb and actually uses mongodb.js, the MongoDB driver. The question is not really which one is better or worse, the question for us is

> Do the benefits of an ODM in Mongoose outweigh the drawbacks?

If you’re looking for an object modeling (ODM) tool so that you do not have to learn a lot about the way Mongodb works, then Mongoose is probably for you. If you want a fast driver and really get the most out of Mongodb, then use the native driver. We know our way around Mongodb so Mongoose would have slowed use down and our app.

Upvotes: 1

Dong Nguyen
Dong Nguyen

Reputation: 1269

mongoose is ORM - Object-relational mapping. It adds an abstract layer with many methods to manipulate data. Such as chaining like this:

Tank
  .find({ size: 'small' })
  .where('createdDate')
  .gt(oneYearAgo)
  .exec(callback);

It may be good for newbies because it's easy to use, with clear syntax. But it may be slower than native approach.

MongoJS is just a wrapper of node-mongodb-native, with some improvements. What is native? It's a driver that allows to directly call to MongoDB from Node.js program. While native version by MongoDB is the best choice for performance, it follows origin syntax same as Mongo Shell, that's quite complicate for newcomers.

Personally, I used Mongoose at first. Now I like to use node-mongodb-native, but have to add some methods to make it easier. Anyway, MongoJS is a balance solution.

Upvotes: 0

thatcoder
thatcoder

Reputation: 367

If you are attempting to connect to a MongoDB database instance, then you will need some sort of driver. I have never heard of a MongoJS, but maybe you are referring to the MongoDB driver? This driver will help you communicate with the database, such as saving documents or retrieving them.

MongooseJS is an object modeling library. It sits on top of the MongoDB driver and manages relationships and object mapping. It can detect changed properties in objects, and then run validation and update operations.

You don't need to explicitly install both, as Mongoose will include the MongoDB driver when installing through NPM. You don't need either if you are not connecting to a MongoDB database.

Better you prefer mongoose since it comes with both libraries which may used to invoke instances and drivers for mongoDB connection .

Upvotes: 0

Related Questions