Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
112 lines (68 sloc) 3.25 KB
.. include:: /includes/unicode-checkmark.rst
======================
MongoDB Node.js Driver
======================
.. default-domain:: mongodb
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: twocols
Introduction
------------
The official MongoDB Node.js driver provides both callback-based and Promise-based
interaction with MongoDB, allowing applications to take full advantage of the new
features in ES6. The 2.x series of the driver is powered by a brand new core
driver and BSON library.
- `Tutorials <http://mongodb.github.io/node-mongodb-native/3.2/tutorials/main/>`__
- `Usage Guide <http://mongodb.github.io/node-mongodb-native/3.2/reference/main/>`__
- `API Reference <http://mongodb.github.io/node-mongodb-native/3.2/api/>`_
- `Changelog <http://mongodb.github.io/node-mongodb-native/3.2/upgrade-migration/main/>`__
- `Source Code <https://github.com/mongodb/node-mongodb-native>`__
Take the free online course taught by MongoDB
---------------------------------------------
.. list-table::
* - .. cssclass:: bordered-figure
.. figure:: /figures/M220JS_hero.jpg
- `M220JS: MongoDB for JavaScript Developers <https://university.mongodb.com/courses/M220JS/about>`__
Learn the essentials of Node.js application development with MongoDB.
Installation
------------
The recommended way to get started using the Node.js 2.0 driver is by using
`NPM (Node Package Manager) <https://www.npmjs.com/>`__ to install the dependency in your project.
After you’ve created your project with ``npm init``, you can install the MongoDB driver and its dependencies
with the command:
.. code-block:: sh
npm install mongodb --save
This will download the MongoDB driver and add a dependency entry in your package.json file.
Connect to MongoDB Atlas
------------------------
To connect to a `MongoDB Atlas <https://docs.atlas.mongodb.com/>`_ cluster, use the
`Atlas connection string <https://docs.atlas.mongodb.com/driver-connection>`__ for your cluster:
.. code-block:: javascript
const MongoClient = require('mongodb').MongoClient;
const uri = "mongodb+srv://<username>:<password>@<your-cluster-url>/test?retryWrites=true&w=majority";
const client = new MongoClient(uri, { useNewUrlParser: true });
client.connect(err => {
const collection = client.db("test").collection("devices");
// perform actions on the collection object
client.close();
});
See `Connect to MongoDB <http://mongodb.github.io/node-mongodb-native/3.2/tutorials/connect/>`__
for more ways to connect.
Compatibility
-------------
MongoDB Compatibility
~~~~~~~~~~~~~~~~~~~~~
.. include:: /includes/mongodb-compatibility-table-node.rst
.. include:: /includes/older-server-versions-unsupported.rst
Language Compatibility
~~~~~~~~~~~~~~~~~~~~~~
.. include:: /includes/extracts/node-driver-compatibility-matrix-language.rst
.. include:: /includes/language-compatibility-table-node.rst
How to get help
---------------
- Join our `Google Group <http://groups.google.com/group/mongodb-user>`__.
- Ask on `Stack Overflow <http://stackoverflow.com/questions/tagged/mongodb+nodejs>`__.
- Visit our `Support Channels <http://www.mongodb.org/about/support>`__.
- See `Issues & Help <http://mongodb.github.io/node-mongodb-native/3.2/issues-help/>`__.
You can’t perform that action at this time.