CRUD operations with Node.js and MongoDB

1.1k views Asked by At

What is the optimal way to perform CRUD operations when using Node.js with MongoDB. Can I reuse the same queries that work on mongo shell? What advantages does a ODM like mongoose provide? Any other ODMs which fit into the mean.io stack?

2

There are 2 answers

0
augustoccesar On

vmr. Well, I guess it depends of what you want to do.

Lets take what Mongoose says in their website:

Mongoose provides a straight-forward, schema-based solution to modeling your application data and includes built-in type casting, validation, query building, business logic hooks and more, out of the box.

Resuming what I understood of that it helps you to model your database and helps you to mantain your logic organized using model like in an MVC. It's a very mature ODM and very recomended for using with MVC.

In my personal experience I started using Monk, which did the trick for a while, but the I started to need to use aggregate and other stuff that apparently Monk can't handle. And I don't wanted to tie my system to an model because is a very mutable project, so I started using Mongoskin which is, at least for now, perfect for me because I can use pratically the same query that I use at Robomongo (Which is like a Navicat, PgAdmin, PhpMyAdmin but for MongoDB) in my ExpressJs code.

0
Krishna On

Mongoose is saving your time by mapping the JavaScript Data objects to the MongoDB database.

MongoDB and NodeJS Integration