Why do I need Mongoose or Mongojs for Node.js?
Asked Answered
G

3

27

Major Questions

Currently I'm very confused, the main questions are: What is the use of Mongoose/Mongojs? What would be different if I run Node.js without Mongoose/Mongojs?

I can't find any good explanation of the big picture of how Mongoose or Mongojs fits together with Node.js.

Mongoose's slogan: "elegant mongodb object modeling for node.js" is not helping.

Minor Questions

Btw, I think Mongoose and Mongojs are doing the same type of thing for Node.js (i.e. interchangeable), but this page seems to be describing Mongojs quite differently from Mongoose: "Simple driver that emulates the mongodb API as much as possible." So I might be wrong in putting Mongoose and Mongojs together. If so, please clarify as well.


Maybe I shouldn't use Mongojs since stackoverflow doesn't even have a tag for it. If so, just ignore everything I said above about Mongojs.


While on the topic of giving the big picture of Node.js with Mongoose and Mongojs, what else on this page should I know?

Thanks.

Giraud answered 4/5, 2013 at 23:48 Comment(0)
O
18

If you're not using MongoDB, the database, then there is no need to have any type of driver/odm solution. NodeJS will run just fine without these.

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.

Long story short: 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.

Oomph answered 5/5, 2013 at 0:16 Comment(1)
Mongojs is another driver, simpler than Mongoose: github.com/gett/mongojsGiraud
A
34

Luis Elizondo said:

Quick post. I’ve been using Node.js a lot, to be honest, I love it, along with Node, I’ve been using MongoDB which, as you may know if you read my last post, doesn’t support joins.

My first choice on a project was to use mongojs because it was plain simple. It uses the same structure you use on MongoDB directly with a very few exceptions, the main one is the ability to pass a callback as an argument.

I moved really fast with mongojs, but then I hit a wall. Joins. Is just not possible to do it with MongoJS for the same reason you can’t do it with MongoDB, you have to use some sort of black magic to do them, and this is when Mongoose excells.

To be honest, I tried to avoid Mongoose because I thought it was hard to use, defining a model was just “a waste of time” when with MongoJS you don’t need to. I was wrong.

Bottom line. If your project is really simple, no joins, no complicated features, go with MongoJS, is really easy but limited. If you’re trying to save the world with your crazy idea and you need more powers than Superman, spend some time learning Mongoose and use it, it will take you there.

Trust me, I just spent two days rewriting everything using Mongoose, I wish someone told me before.

http://luiselizondo.net/blogs/luis-elizondo/mongoose-vs-mongojs-nodejs

Altagraciaaltaic answered 12/4, 2014 at 19:48 Comment(0)
O
18

If you're not using MongoDB, the database, then there is no need to have any type of driver/odm solution. NodeJS will run just fine without these.

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.

Long story short: 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.

Oomph answered 5/5, 2013 at 0:16 Comment(1)
Mongojs is another driver, simpler than Mongoose: github.com/gett/mongojsGiraud
S
8

If you are going to use MongoDB as a database with Node.js in your application then you will use Mongoose or MongoJS to perform database related operations like connecting to MongoDB database, performing CRUD operations and many more database operations.

Mongoose: is a Node.js library that provides MongoDB object mapping similar to ORM with a familiar interface within Node.js. Mongoose is a great ODM(Object Document Mapping), it means Mongoose translate data in the database to JavaScript objects for use in your application.

Mongoose provides straight-forward, schema-based solutions to model your application data. It include built in type-casting, validation, query building,business logic hooks and more, out of the box

MongoJS: is a Node.js module for MongoDB that emulates official MongoDB API as much as possible.It wraps MongoDB native and its very easy to use.

Scalise answered 9/9, 2016 at 11:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.