MongoDB Node.js Driver


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.

Take the free online course taught by MongoDB


M220JS: MongoDB for JavaScript Developers

Learn the essentials of Node.js application development with MongoDB.


The recommended way to get started using the Node.js 2.0 driver is by using NPM (Node Package Manager) 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:

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 cluster, use the Atlas connection string for your cluster:

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

See Connect to MongoDB for more ways to connect.


MongoDB Compatibility

Node.js Driver MongoDB 4.2 MongoDB 4.0 MongoDB 3.6 MongoDB 3.4 MongoDB 3.2 MongoDB 3.0 MongoDB 2.6
>= 3.3
>= 3.2.1  
>= 3.1  
>= 3.0    

The driver does not support older versions of MongoDB.

Language Compatibility

The following compatibility table specifies the recommended version(s) of the MongoDB Node.js driver for use with a specific version of Node.js.

The first column lists the driver version(s).

Node.js Driver Node.js v0.8.X Node.js v0.10.X Node.js v0.12.X Node.js v4.X.X Node.js v6.X.X Node.js v8.X.X Node.js v10.x.x

How to get help