最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - What is the best way to use mongoDB with node.js? - Stack Overflow

programmeradmin4浏览0评论

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.

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.

Share Improve this question edited Mar 16, 2012 at 17:58 rob asked Mar 16, 2012 at 4:57 robrob 10.1k7 gold badges44 silver badges73 bronze badges 3
  • 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 es with the official 10gen package. So it is not redundant and it does act like a client from the perspective of the database server. – Ren Commented Mar 16, 2012 at 18:12
  • 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. – Jonathan Rowny Commented Mar 16, 2012 at 19:10
  • 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. – rob Commented Mar 16, 2012 at 20:08
Add a ment  | 

1 Answer 1

Reset to default 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./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.

发布评论

评论列表(0)

  1. 暂无评论