发布于 2015-09-14 14:40:16 | 481 次阅读 | 评论: 0 | 来源: 网络整理
You use Node.js to write event-driven, scalable network programs in server-side JavaScript. Node.js runs on Google’s V8. This section describes the available tools and suggested practices for using Node.js with MongoDB. For a more detailed discussion, see the Node.js Driver Manual.
The following are the README and source code:
The MongoDB Node.js driver is the 10gen-supported driver for MongoDB. In Spring 2012, 10gen officially adopted the popular Node MongoDB Native Project and sponsored the maintainer, Christian Kvalheim, to continue its development. It is written in pure JavaScript and provides a native asynchronous Node.js interface to MongoDB. The driver is optimized for simplicity. It can be used on its own, but it also serves as the basis of several object mapping libraries, such as Mongoose.
Because MongoDB is so easy to use, the basic Node.js driver can be the best solution for many applications. However, if you need validations, associations, and other high-level data modeling functions, then an Object Document Mapper may be helpful.
Mongoose is the 10gen-supported ODM for Node.js. It has a thriving open source community and includes advanced schema-based features such as async validation, casting, object life-cycle management, pseudo-joins, and rich query builder support.
Install it easily with npm:
npm install mongoose
The following are related resources:
Each of these projects build on top of the native Node.js driver, and so some knowledge of that is useful, especially if you work with a custom MongoDB configuration.
A few 3rd party drivers exist. While not officially supported by 10gen, these drivers take a different approach that may be valuable given your needs.