What is the best way to use mongoDB with node.js?
Asked Answered
S

1

15

I need to run MongoDB with node.js both locally, and on cloud services such as Nodester and MongoHQ. I would like to have minimal dependencies, for instance I don't really want to use Express or Mongoose right now. Basically, I'd like to run it as "directly" as possible

I have installed Mongo locally using Macports, and then using Mongojs module to talk to it from my node.js app. That works okay, running locally. But I see that Mongojs is supposedly wrapping the mongo-native module. Does that make it redundant with the Macports installation of Mongo, or is mongo-native just a client? And will Mongojs work to talk to a database hosted on MongoHQ, from an app hosted on Nodester? Finally, is Mongojs a good choice, or is there a better one?

I guess there are just so many interconnected things that I am getting confused and would like an explanation of how they all fit together and what standard practices are. For what it's worth , this is for a personal project, but I'd like to make it public, so I need for it to work with cheap or free hosting services.

Shied answered 16/3, 2012 at 4:57 Comment(3)
Mongo-native is a Node.js driver for MongoDB and it is different from the mongo binary (which for one, runs on SpiderMonkey by default and does not do asynchronous IO) that comes with the official 10gen package. So it is not redundant and it does act like a client from the perspective of the database server.Childers
I guess its a good idea to avoid too many dependencies but NPM makes it relatively painless to manage dependencies and in NodeJS world... dependencies happen! I only mention it because I've used Mongoose quite a bit and its just incredibly painless. For me personally, the benefits far outweigh the risks.Ebony
I understand what you mean @JonathanRowny, I guess I tend to try to start out a bit closer to the metal, so I understand what I'm doing better. I guess its really less a matter of dependencies, and more one of layers. Once I do a small project using Mongo a bit more directly, I will look into using Mongoose for the next project. Mongojs seems about the right level of abstraction for me, but it doesn't seem very popular, so I might just skip it and use mongo-native.Shied
T
15

It depends on your needs. I'm the author of the mongodb native driver and I would say that if you don't have very specific performance needs mongoose might make sense since it lets you do a bit of modeling for your documents and is closer to the concept of an ODM. For the wrapper you are using there are a whole bunch of them. Have a look at

http://mongodb.github.io/node-mongodb-native/

and

https://github.com/christkv/node-mongodb-native

I've tried to add all projects that might be relevant and each time I build the docs it pulls in stats to mark the projects as active or not.

If you need raw performance use my driver directly or one of the thin wrappers around it like mongojs or mongoskin.

I'm talking with Aaron one of the mongoose writers about maybe trying to create a framework half way between mongoose and the driver, but it's just a talk at the moment.

Trabeated answered 26/3, 2012 at 7:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.