OPTIONS

Node.js Language Center

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:

Node.js Driver

The MongoDB Node.js driver is the officially supported node.js driver for MongoDB. In Spring 2012, MongoDB 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.

Install or Upgrade

The easiest way to install is to use npm:

npm install mongodb

Object Mappers

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

Mongoose is the officially 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:

Other Notable Projects

  • Mongoskin: Layer for node-mongodb-native.
  • Mongolia: Lightweight MongoDB ORM/driver wrapper.
  • Mongojs: Somewhat mimics the MongoDB shell api.

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.

3rd Party Drivers

A few 3rd party drivers exist. While not officially supported, these drivers take a different approach that may be valuable given your needs.

  • node-mongodb <https://github.com/orlandov/node-mongodb>: An asynchronous Node interface to MongoDB, written in C.
  • Mongolian DeadBeef: A Node.js driver that attempts to approximate the MongoDB shell.