Permalink
Fetching contributors…
Cannot retrieve contributors at this time
209 lines (143 sloc) 6.14 KB
.. _node-js-language-center:
======================
Node.js MongoDB Driver
======================
.. default-domain:: mongodb
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: twocols
You use `Node.js <http://nodejs.org/>`_ 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 the official MongoDB Node.js Driver reference, see:
- `Node.js Driver Manual <http://mongodb.github.com/node-mongodb-native/2.1>`_.
The following are the README and source code:
- `Node.js README <https://github.com/mongodb/node-mongodb-native/blob/master/Readme.md>`_
- `Node.js source code <https://github.com/mongodb/node-mongodb-native>`_
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 <https://github.com/mongodb/node-mongodb-native>`_
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 <http://mongoosejs.com/>`_.
Install or Upgrade
~~~~~~~~~~~~~~~~~~
The easiest way to install is to use `npm <https://npmjs.org/>`_:
.. code-block:: sh
npm install mongodb
MongoDB Compatibility
~~~~~~~~~~~~~~~~~~~~~~
.. include:: /includes/extracts/node-driver-compatibility-matrix-mongodb.rst
.. list-table::
:header-rows: 1
:stub-columns: 1
:widths: 20 20 20 20 20
:class: compatibility
* - Node.js Driver
- MongoDB 2.4
- MongoDB 2.6
- MongoDB 3.0
- MongoDB 3.2
* - >=2.1.0
- |checkmark|
- |checkmark|
- |checkmark|
- |checkmark|
* - >=2.0.14
- |checkmark|
- |checkmark|
- |checkmark|
-
.. include:: /includes/extracts/node-driver-compatibility-full-mongodb.rst
.. include:: /includes/older-server-versions-unsupported.rst
Language Compatibility
~~~~~~~~~~~~~~~~~~~~~~
.. include:: /includes/extracts/node-driver-compatibility-matrix-language.rst
.. list-table::
:header-rows: 1
:stub-columns: 1
:class: compatibility
* - Node.js Driver
- Node.js v0.8.X
- Node.js v0.10.X
- Node.js v0.12.X
- Node.js v4.X.X
* - 2.1.X
- |checkmark|
- |checkmark|
- |checkmark|
- |checkmark|
* - 2.0.X
- |checkmark|
- |checkmark|
- |checkmark|
- |checkmark|
.. include:: /includes/extracts/node-driver-compatibility-full-language.rst
.. include:: /includes/unicode-checkmark.rst
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 <http://mongoosejs.com/>`_ is an 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 <https://npmjs.org/>`_:
.. code-block:: sh
npm install mongoose
The following are related resources:
- `Mongoose MongoDB ODM <https://npmjs.org/package/mongoose>`_
- `Mongoose plugins <http://plugins.mongoosejs.com/>`_
- `Quickstart Tutorial <http://mongoosejs.com/docs/index.html>`_
- `Source Code <https://github.com/learnboost/mongoose>`_
- `Google Group <https://groups.google.com/forum/?fromgroups#!forum/mongoose-orm>`_
- `Bug reports <https://github.com/learnboost/mongoose/issues>`_
- IRC: #mongoosejs on `freenode <http://webchat.freenode.net/>`_
Other Notable Projects
----------------------
.. default-domain:: mongodb
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: twocols
- `Mongoskin <https://github.com/kissjs/node-mongoskin>`_: Layer for node-mongodb-native.
- `crudlet-mongodb <https://github.com/mojo-js/crudlet-mongodb>`_: Streamable interface for mongodb.
- `Mongolia <https://github.com/masylum/mongolia>`_: Lightweight MongoDB ORM/driver wrapper.
- `Mongojs <https://github.com/gett/mongojs>`_: Somewhat mimics the MongoDB shell api.
- `MongoSmash <http://github.com/bengl/mongosmash>`_: Uses Harmony's ``Object.observe()``.
- `Camo <https://github.com/scottwrobinson/camo>`_: A class-based ES6 ODM for MongoDB.
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.
Tutorials
---------
- `Mongoskin Tutorial <http://www.hacksparrow.com/mongoskin-tutorial-with-examples.html>`_
- `Mongoose Tutorial <http://mongoosejs.com/docs/index.html>`_
- `Camo Tutorial <http://stackabuse.com/getting-started-with-camo/>`_
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 <https://github.com/marcello3d/node-mongolian>`_:
A Node.js driver that attempts to approximate the MongoDB shell.
.. REMOVED PRESENTATIONS:
* [An introduction to the mongo node.js driver|https://www.mongodb.com/presentation/mongohamburg-2011/an-introduction-nodejs-mongodb-driver] - June 2011
* [Using MongoDB with node.js|https://www.mongodb.com/presentation/mongodc-2011/using-mongodb-with-nodejs] - June 2011
* [Node.js & MongoDB|http://www.mongodb.com/presentations/webinar/node.js-and-mongodb-a-panel-discussion] - Webinar June 2011
* [A beautiful marriage: MongoDB and node.js|http://www.mongodb.com/presentation/mongonyc-2011/mongodb-and-nodejs] - MongoNYC June 2011
* [Rapid Realtime App Development with Node.JS & MongoDB|http://www.mongodb.com/presentation/mongosf2011/nodejs] - MongoSF May 2011