diff --git a/docs/reference/content/reference/connecting/connection-settings.md b/docs/reference/content/reference/connecting/connection-settings.md
index 86605da4fa..d71a6fe7c5 100644
--- a/docs/reference/content/reference/connecting/connection-settings.md
+++ b/docs/reference/content/reference/connecting/connection-settings.md
@@ -13,20 +13,22 @@ title = "Connection Settings"
Optional connection settings are settings not covered by the [URI Connection String ](https://docs.mongodb.org/manual/reference/connection-string/). The following options are passed in the options parameter in the MongoClient.connect function.
```js
-var MongoClient = require('mongodb').MongoClient
- , assert = require('assert');
+const MongoClient = require('mongodb').MongoClient;
+const assert = require('assert');
// Connection URL
-var url = 'mongodb://localhost:50000,localhost:50001/myproject';
+const url = 'mongodb://localhost:50000,localhost:50001';
+// Database Name
+const dbName = 'myproject';
// Use connect method to connect to the Server passing in
// additional options
MongoClient.connect(url, {
poolSize: 10, ssl: true
-}, function(err, db) {
+}, function(err, client) {
assert.equal(null, err);
console.log("Connected correctly to server");
- db.close();
+ client.close();
});
```
@@ -35,12 +37,12 @@ The table below shows all settings and what topology they affect.
| Option | Affects | Type | Default | Description |
| :----------| :------------------ | :------ | :------ |:------------- |
| **poolSize** | Server, ReplicaSet, Mongos | integer | 5 | Set the maximum poolSize for each individual server or proxy connection.|
-| **ssl** | Server, ReplicaSet, Mongos | boolean | false | Use ssl connection (needs to have a mongod server with ssl support) |
-| **sslValidate** | Server, ReplicaSet, Mongos | boolean | true | Validate mongod server certificate against ca (needs to have a mongod server with ssl support, 2.4 or higher) |
-| **sslCA** | Server, ReplicaSet, Mongos | Array | null | Array of valid certificates either as Buffers or Strings (needs to have a mongod server with ssl support, 2.4 or higher) |
-| **sslCert** | Server, ReplicaSet, Mongos | Buffer/String | null | String or buffer containing the certificate we wish to present (needs to have a mongod server with ssl support, 2.4 or higher) |
-| **sslKey** | Server, ReplicaSet, Mongos | Buffer/String | null | String or buffer containing the certificate private key we wish to present (needs to have a mongod server with ssl support, 2.4 or higher) |
-| **sslPass** | Server, ReplicaSet, Mongos | Buffer/String | null | String or buffer containing the certificate password (needs to have a mongod server with ssl support, 2.4 or higher) |
+| **ssl** | Server, ReplicaSet, Mongos | boolean | false | Use ssl connection |
+| **sslValidate** | Server, ReplicaSet, Mongos | boolean | true | Validate mongod server certificate against ca |
+| **sslCA** | Server, ReplicaSet, Mongos | Array | null | Array of valid certificates either as Buffers or Strings |
+| **sslCert** | Server, ReplicaSet, Mongos | Buffer/String | null | String or buffer containing the certificate we wish to present |
+| **sslKey** | Server, ReplicaSet, Mongos | Buffer/String | null | String or buffer containing the certificate private key we wish to present |
+| **sslPass** | Server, ReplicaSet, Mongos | Buffer/String | null | String or buffer containing the certificate password |
| **autoReconnect** | Server | boolean | true | Reconnect on error. |
| **noDelay** | Server, ReplicaSet, Mongos | boolean | true | TCP Socket NoDelay option. |
| **keepAlive** | Server, ReplicaSet, Mongos | integer | 30000 | The number of milliseconds to wait before initiating keepAlive on the TCP socket. |
diff --git a/docs/reference/content/reference/connecting/legacy-connection-settings.md b/docs/reference/content/reference/connecting/legacy-connection-settings.md
deleted file mode 100644
index 1143d7c052..0000000000
--- a/docs/reference/content/reference/connecting/legacy-connection-settings.md
+++ /dev/null
@@ -1,285 +0,0 @@
-+++
-date = "2015-03-19T12:53:30-04:00"
-title = "Legacy Connection Settings"
-[menu.main]
- parent = "Connection Options"
- identifier = "Legacy Connection Settings"
- weight = 40
- pre = ""
-+++
-
-# Connect To MongoDB (Legacy)
-
-{{% note %}}
-
-For 2.1.10 or earlier. For newer versions, see [Connect to MongoDB]({{< relref
-"reference/connecting/index.md" >}})
-{{% /note %}}
-
-Connecting to MongoDB using the driver is primarily done using the `MongoClient.connect` method and a URI. Let's look at how we connect to a couple of different server topologies.
-
-## Single Server Connection
-
-We have a single MongoDB server instance running on the port *27017* Let's connect using the driver and *MongoClient.connect*
-
-```js
-var MongoClient = require('mongodb').MongoClient
- , assert = require('assert');
-
-// Connection URL
-var url = 'mongodb://localhost:27017/myproject';
-// Use connect method to connect to the Server
-MongoClient.connect(url, function(err, db) {
- assert.equal(null, err);
- console.log("Connected correctly to server");
-
- db.close();
-});
-```
-
-Let's break down the `URI` string we passed as the first argument to MongoClient.connect.
-
-| Parameter | Description |
-| :----------| :------------- |
-| `mongodb://` | is the protocol definition |
-| `localhost:27017` | is the server we are connecting to |
-| `/myproject` | is the database we wish to connect to |
-
-## Replicaset Server Connection
-
-We wish to connect to a ReplicaSet consisting of one primary and 1 or more secondaries. To Do this we need to supply the driver with a seedlist of servers and the name of the ReplicaSet we wish to connect to. Let's take a look at a code example.
-
-```js
-{{% connect-to-replicaset %}}
-```
-
-Let's break down the `URI` string.
-
-| Parameter | Description |
-| :----------| :------------- |
-| `mongodb://` | is the protocol definition |
-| `localhost:27017,localhost:27018` | is the servers we are connecting to to discover the topology of the ReplicaSet. |
-| `/myproject` | is the database we wish to connect to |
-| `replicaSet=foo` | is the name of the ReplicaSet we are connecting to. This ensures we are connecting to the correct Replicaset. **This is a required parameter when using the 2.0 driver** |
-
-## Mongos Proxy Connection
-
-We wish to connect to a set of `mongos` proxies. Just as in the case of connecting to a ReplicaSet we can provide a seed list of `mongos` proxies. This allows the driver to perform failover between proxies automatically in case of a proxy process having been shut down. Let's look at an example of code connecting to a set of proxies.
-
-```js
-var MongoClient = require('mongodb').MongoClient
- , assert = require('assert');
-
-// Connection URL
-var url = 'mongodb://localhost:50000,localhost:50001/myproject';
-// Use connect method to connect to the Server
-MongoClient.connect(url, function(err, db) {
- assert.equal(null, err);
- console.log("Connected correctly to server");
-
- db.close();
-});
-```
-
-Let's break down the `URI` string.
-
-| Parameter | Description |
-| :----------| :------------- |
-| `mongodb://` | is the protocol definition |
-| `localhost:50000,localhost:50001` | is the *mongos* proxies we are connecting to. |
-| `/myproject` | is the database we wish to connect to |
-
-Let's break down the `URI` string.
-
-| Parameter | Description |
-| :----------| :------------- |
-| `mongodb://` | is the protocol definition |
-| `dave:password` | is the user name and password for the database |
-| `localhost:27017` | is the server we are connecting to |
-| `/myproject` | is the database we wish to connect to |
-| `authSource=admin` | is the database we wish to authenticate against |
-
-# MongoClient.connect Optional Parameters
-
-The driver has many more options for tweaking than what's available through the `URI` specification. These can be passed to the driver using an optional parameters object. The top level fields in the options object are.
-
-| Parameter | Description |
-| :----------| :------------- |
-| `db` | Options that affect the Db instance returned by the MongoClient.connect method. |
-| `replSet` | Options that modify the Replicaset topology connection behavior. **This is a required parameter when using the 2.0 driver** |
-| `mongos` | Options that modify the Mongos topology connection behavior. |
-| `server` | Options that modify the Server topology connection behavior. |
-
-A simple example connecting to a single server setting all returned queries to be raw BSON buffers and adjusting the poolSize to be 10 connections for this connection.
-
-```js
-var MongoClient = require('mongodb').MongoClient
- , assert = require('assert');
-
-// Connection URL
-var url = 'mongodb://dave:password@localhost:27017/myproject';
-// Use connect method to connect to the Server
-MongoClient.connect(url, {
- db: {
- raw: true
- },
- server: {
- poolSize: 10
- }
- }, function(err, db) {
- assert.equal(null, err);
- console.log("Connected correctly to server");
-
- db.close();
-});
-```
-
-Let's look at the individual options for each of the top level fields.
-
-## Data base level options
-
-| Parameter | Type | Description |
-| :----------| :------------- | :------------- |
-| `w` | {Number/String, > -1 \|\| 'majority'} | the write concern for the operation where < 1 is no acknowledgment of write and w >= 1 or w = 'majority' acknowledges the write |
-| `wtimeout` | {Number, 0} | set the timeout for waiting for write concern to finish (combines with w option) |
-| `fsync` | (Boolean, default:false) | write waits for fsync before returning |
-| `j` | (Boolean, default:false) | write waits for journal sync before returning |
-| `readPreference` | {String} | the preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST). |
-| `readPreferenceTags` | {Object, default:null} | the tags object {'loc':'ny'} used with the readPreference. |
-| `native_parser` | {Boolean, default:false} | use c++ bson parser. |
-| `forceServerObjectId` | {Boolean, default:false} | force server to create _id fields instead of client.|
-| `pkFactory` | {Object} | object overriding the basic ObjectID primary key generation. |
-| `serializeFunctions` | {Boolean, default:false} | serialize functions. |
-| `raw` | {Boolean, default:false} | perform operations using raw bson buffers. |
-| `bufferMaxEntries` | {Number, default: -1} | sets a cap on how many operations the driver will buffer up before giving up on getting a working connection, default is -1 which is unlimited. |
-
-If you are connecting to a MongoDB replicaset, you pass the parameters using the `replset` options field.
-
-```js
-var MongoClient = require('mongodb').MongoClient,
- f = require('util').format,
- fs = require('fs');
-
-MongoClient.connect(f('mongodb://%s@server:27017/test'), {
- db: {
- w:1
- }
-}, function(err, db) {
- db.close();
-});
-
-```
-
-## Individual Server Level Options
-
-| Parameter | Type | Description |
-| :----------| :------------- | :------------- |
-| `poolSize` | {Number, default: 5} | Number of connections in the connection pool for each server instance, set to 5 as default for legacy reasons. |
-| `ssl` | {Boolean, default: false} | Use ssl connection (needs to have a mongod server with ssl support). |
-| `sslValidate` | {Boolean, default: true} | Validate mongod server certificate against ca (needs to have a mongod server with ssl support, 2.4 or higher). |
-| `checkServerIdentity` | {Boolean\|Function, default: true} | Ensure we check server identify during SSL, set to false to disable checking. You can pass in a boolean or your own checkServerIdentity override function. |
-| `sslCA` | {Buffer[]\|string[], default: null} | Array of valid certificates either as Buffers or Strings (needs to have a mongod server with ssl support, 2.4 or higher). |
-| `sslCert` | {Buffer\|string, default: null} | String or buffer containing the certificate we wish to present (needs to have a mongod server with ssl support, 2.4 or higher). |
-| `sslKey` | {Buffer\|string, default: null} | String or buffer containing the certificate private key we wish to present (needs to have a mongod server with ssl support, 2.4 or higher). |
-| `sslPass` | {Buffer\|string, default: null} | String or buffer containing the certificate password (needs to have a mongod server with ssl support, 2.4 or higher). |
-| `autoReconnect` | {Boolean, default: true} | Reconnect on error. |
-| `socketOptions.noDelay` | {Boolean, default: true} | TCP Socket NoDelay option. |
-| `socketOptions.keepAlive` | {Number, default: 30000} | The number of milliseconds to wait before initiating keepAlive on the TCP socket. |
-| `socketOptions.connectTimeoutMS` | {Number, default: 30000} | TCP Connection timeout setting. |
-| `socketOptions.socketTimeoutMS` | {Number, default: 360000} | TCP Socket timeout setting. |
-
-If you are connecting to a single MongoDB instance you pass the parameters using the `server` options field.
-
-```js
-var MongoClient = require('mongodb').MongoClient,
- f = require('util').format,
- fs = require('fs');
-
-MongoClient.connect(f('mongodb://%s@server:27017/test'), {
- server: {
- sslKey:key
- , sslCert:cert
- }
-}, function(err, db) {
- db.close();
-});
-
-```
-
-## Replicaset Level Options
-
-| Parameter | Type | Description |
-| :----------| :------------- | :------------- |
-| `ha` | {Boolean, default:true} | Controls if the replicaset monitoring runs or not. |
-| `haInterval` | {Number, default:10000} | The number of milliseconds between each ping of the replicaset members. The replicaset monitoring process, is the process monitoring the replicaset, detecting new members and reconnecting to existing members. |
-| `replicaSet` | {String} | the name of the replicaset to connect to. **This is a required parameter when using the 2.0 driver** |
-| `secondaryAcceptableLatencyMS` | {Number, default:15} | sets the range of servers to pick when using NEAREST (lowest ping ms + the latency fence, ex: range of 1 to (1 + 15) ms) |
-| `connectWithNoPrimary` | {Boolean, default:false} | Sets if the driver should connect even if no primary is available. |
-| `poolSize` | {Number, default: 5} | Number of connections in the connection pool for each server instance, set to 5 as default for legacy reasons. |
-| `ssl` | {Boolean, default: false} | Use ssl connection (needs to have a mongod server with ssl support). |
-| `sslValidate` | {Boolean, default: true} | Validate mongod server certificate against ca (needs to have a mongod server with ssl support, 2.4 or higher). |
-| `checkServerIdentity` | {Boolean\|Function, default: true} | Ensure we check server identify during SSL, set to false to disable checking. You can pass in a boolean or your own checkServerIdentity override function. |
-| `sslCA` | {Buffer[]\|string[], default: null} | Array of valid certificates either as Buffers or Strings (needs to have a mongod server with ssl support, 2.4 or higher). |
-| `sslCert` | {Buffer\|string, default: null} | String or buffer containing the certificate we wish to present (needs to have a mongod server with ssl support, 2.4 or higher). |
-| `sslKey` | {Buffer\|string, default: null} | String or buffer containing the certificate private key we wish to present (needs to have a mongod server with ssl support, 2.4 or higher). |
-| `sslPass` | {Buffer\|string, default: null} | String or buffer containing the certificate password (needs to have a mongod server with ssl support, 2.4 or higher). |
-| `socketOptions.noDelay` | {Boolean, default: true} | TCP Socket NoDelay option. |
-| `socketOptions.keepAlive` | {Number, default: 30000} | The number of milliseconds to wait before initiating keepAlive on the TCP socket. |
-| `socketOptions.connectTimeoutMS` | {Number, default: 30000} | TCP Connection timeout setting. |
-| `socketOptions.socketTimeoutMS` | {Number, default: 360000} | TCP Socket timeout setting. |
-
-If you are connecting to a MongoDB replicaset, you pass the parameters using the `replset` options field.
-
-```js
-var MongoClient = require('mongodb').MongoClient,
- f = require('util').format,
- fs = require('fs');
-
-MongoClient.connect(f('mongodb://%s@server:27017/test'), {
- replset: {
- sslKey:key
- , sslCert:cert
- }
-}, function(err, db) {
- db.close();
-});
-
-```
-
-## Mongos Proxy Level Options
-
-| Parameter | Type | Description |
-| :----------| :------------- | :------------- |
-| `ha` | {Boolean, default:true} | turn on high availability. |
-| `haInterval` | {Number, default:5000} | time between each replicaset status check. |
-| `secondaryAcceptableLatencyMS` | {Number, default:15} | sets the range of servers to pick when using NEAREST (lowest ping ms + the latency fence, ex: range of 1 to (1 + 15) ms) |
-| `poolSize` | {Number, default: 5} | Number of connections in the connection pool for each server instance, set to 5 as default for legacy reasons. |
-| `ssl` | {Boolean, default: false} | Use ssl connection (needs to have a mongod server with ssl support). |
-| `sslValidate` | {Boolean, default: true} | Validate mongod server certificate against ca (needs to have a mongod server with ssl support, 2.4 or higher). |
-| `checkServerIdentity` | {Boolean\|Function, default: true} | Ensure we check server identify during SSL, set to false to disable checking. You can pass in a boolean or your own checkServerIdentity override function. |
-| `sslCA` | {Buffer[]\|string[], default: null} | Array of valid certificates either as Buffers or Strings (needs to have a mongod server with ssl support, 2.4 or higher). |
-| `sslCert` | {Buffer\|string, default: null} | String or buffer containing the certificate we wish to present (needs to have a mongod server with ssl support, 2.4 or higher). |
-| `sslKey` | {Buffer\|string, default: null} | String or buffer containing the certificate private key we wish to present (needs to have a mongod server with ssl support, 2.4 or higher). |
-| `sslPass` | {Buffer\|string, default: null} | String or buffer containing the certificate password (needs to have a mongod server with ssl support, 2.4 or higher). |
-| `socketOptions.noDelay` | {Boolean, default: true} | TCP Socket NoDelay option. |
-| `socketOptions.keepAlive` | {Number, default: 30000} | The number of milliseconds to wait before initiating keepAlive on the TCP socket. |
-| `socketOptions.connectTimeoutMS` | {Number, default: 30000} | TCP Connection timeout setting. |
-| `socketOptions.socketTimeoutMS` | {Number, default: 360000} | TCP Socket timeout setting. |
-
-If you are connecting to a MongoDB replicaset, you pass the parameters using the `mongos` options field.
-
-```js
-var MongoClient = require('mongodb').MongoClient,
- f = require('util').format,
- fs = require('fs');
-
-MongoClient.connect(f('mongodb://%s@server:27017/test'), {
- mongos: {
- sslKey:key
- , sslCert:cert
- }
-}, function(err, db) {
- db.close();
-});
-
-```
diff --git a/docs/reference/content/reference/ecmascript6/connecting.md b/docs/reference/content/reference/ecmascript6/connecting.md
deleted file mode 100644
index 79cdc7a2ac..0000000000
--- a/docs/reference/content/reference/ecmascript6/connecting.md
+++ /dev/null
@@ -1,32 +0,0 @@
-+++
-date = "2015-03-19T12:53:30-04:00"
-title = "Connecting"
-[menu.main]
- parent = "ECMAScript 6"
- identifier = "Connection"
- weight = 60
- pre = ""
-+++
-
-# Connecting
-
-The MongoClient connection method returns a Promise if no callback is passed to it. Below is an example using the [co](https://www.npmjs.com/package/co) package to run a `generator` function, which is one of the most exciting innovations of ECMAScript 6.
-
-```js
-var MongoClient = require('mongodb').MongoClient,
- co = require('co'),
- assert = require('assert');
-
-co(function*() {
- // Connection URL
- var url = 'mongodb://localhost:27017/myproject';
- // Use connect method to connect to the Server
- var db = yield MongoClient.connect(url);
- // Close the connection
- db.close();
-}).catch(function(err) {
- console.log(err.stack);
-});
-```
-
-The `MongoClient.connect` function returns a `Promise` that we then execute using the `yield` keyword of the `generator` function. If an error happens during the `MongoClient.connect` the error is caught by `co` and can be inspected by attaching a function to the `catch` method as shown above.
diff --git a/docs/reference/content/reference/ecmascript6/crud.md b/docs/reference/content/reference/ecmascript6/crud.md
deleted file mode 100644
index c34b87499e..0000000000
--- a/docs/reference/content/reference/ecmascript6/crud.md
+++ /dev/null
@@ -1,418 +0,0 @@
-+++
-date = "2015-03-19T12:53:30-04:00"
-title = "CRUD Operations"
-[menu.main]
- parent = "ECMAScript 6"
- identifier = "CRUD"
- weight = 70
- pre = ""
-+++
-
-# ECMAScript 6 CRUD
-
-Let's take a look at the CRUD operations from the perspective of ECMAScript 6. In this guide we will be using the same examples as in the general CRUD specification overview but rewrite them to use the new ECMAScript 6 features. For all method options refer to the main CRUD tutorial.
-
-- [CRUD]({{}}): CRUD Specification.
-
-This reference also omits methods that no longer make sense when using ECMAScript 6 such as the `each` and `forEach` methods.
-
-## Inserting Documents
-The *insertOne* and *insertMany* methods exists on the *Collection* class and is used to insert documents into MongoDB. Code speaks a thousand words so let's see two simple examples of inserting documents.
-
-```js
-var MongoClient = require('mongodb').MongoClient,
- co = require('co'),
- assert = require('assert');
-
-co(function*() {
- // Connection URL
- var db = yield MongoClient.connect('mongodb://localhost:27017/myproject');
- console.log("Connected correctly to server");
-
- // Insert a single document
- var r = yield db.collection('inserts').insertOne({a:1});
- assert.equal(1, r.insertedCount);
-
- // Insert multiple documents
- var r = yield db.collection('inserts').insertMany([{a:2}, {a:3}]);
- assert.equal(2, r.insertedCount);
-
- // Close connection
- db.close();
-}).catch(function(err) {
- console.log(err.stack);
-});
-```
-
-Let's look at a simple example where we are writing to a replicaset and we wish to ensure that we serialize a passed in function as well as have the server assign the *_id* for each document.
-
-```js
-var MongoClient = require('mongodb').MongoClient,
- co = require('co'),
- assert = require('assert');
-
-co(function*() {
- // Connection URL
- var db = yield MongoClient.connect('mongodb://localhost:27017/myproject');
- console.log("Connected correctly to server");
-
- // Insert a single document
- var r = yield db.collection('inserts').insertOne({
- a:1
- , b: function() { return 'hello'; }
- }, {
- w: 'majority'
- , wtimeout: 10000
- , serializeFunctions: true
- , forceServerObjectId: true
- });
-
- assert.equal(1, r.insertedCount);
- db.close();
-}).catch(function(err) {
- console.log(err.stack);
-});
-```
-
-That wraps up the *insert* methods. Next let's look at the *update* methods.
-
-## Updating Documents
-The *updateOne* and *updateMany* methods exists on the *Collection* class and is used to update and upsert documents into MongoDB. Let's look at a couple of usage examples.
-
-```js
-var MongoClient = require('mongodb').MongoClient,
- co = require('co'),
- assert = require('assert');
-
-co(function*() {
- // Connection URL
- var db = yield MongoClient.connect('mongodb://localhost:27017/myproject');
- console.log("Connected correctly to server");
-
- // Get the updates collection
- var col = db.collection('updates');
- // Insert a single document
- var r = yield col.insertMany([{a:1}, {a:2}, {a:2}]);
- assert.equal(3, r.insertedCount);
-
- // Update a single document
- var r = yield col.updateOne({a:1}, {$set: {b: 1}});
- assert.equal(1, r.matchedCount);
- assert.equal(1, r.modifiedCount);
-
- // Update multiple documents
- var r = yield col.updateMany({a:2}, {$set: {b: 1}});
- assert.equal(2, r.matchedCount);
- assert.equal(2, r.modifiedCount);
-
- // Upsert a single document
- var r = yield col.updateOne({a:3}, {$set: {b: 1}}, {
- upsert: true
- });
- assert.equal(0, r.matchedCount);
- assert.equal(1, r.upsertedCount);
- db.close();
-}).catch(function(err) {
- console.log(err.stack);
-});
-```
-
-## Removing Documents
-The *deleteOne* and *deleteMany* methods exist on the *Collection* class and is used to remove documents from MongoDB. Let's look at a couple of usage examples.
-
-```js
-var MongoClient = require('mongodb').MongoClient,
- co = require('co'),
- assert = require('assert');
-
-co(function*() {
- // Connection URL
- var db = yield MongoClient.connect('mongodb://localhost:27017/myproject');
- console.log("Connected correctly to server");
-
- // Get the removes collection
- var col = db.collection('removes');
- // Insert a single document
- var r = yield col.insertMany([{a:1}, {a:2}, {a:2}]);
- assert.equal(3, r.insertedCount);
-
- // Remove a single document
- var r = yield col.deleteOne({a:1});
- assert.equal(1, r.deletedCount);
-
- // Update multiple documents
- var r = yield col.deleteMany({a:2});
- assert.equal(2, r.deletedCount);
- db.close();
-}).catch(function(err) {
- console.log(err.stack);
-});
-```
-
-## findOneAndUpdate, findOneAndDelete and findOneAndReplace
-The three methods *findOneAndUpdate*, *findOneAndDelete* and *findOneAndReplace* are special commands that allows the user to update or upsert a document and have the modified or existing document returned. It comes at a cost as the operation takes a write lock for the duration of the operation as it needs to ensure the modification is *atomic*. Let's look at *findOneAndUpdate* first using an example.
-
-```js
-var MongoClient = require('mongodb').MongoClient,
- co = require('co'),
- assert = require('assert');
-
-co(function*() {
- // Connection URL
- var db = yield MongoClient.connect('mongodb://localhost:27017/myproject');
- console.log("Connected correctly to server");
-
- // Get the findAndModify collection
- var col = db.collection('findAndModify');
- // Insert a single document
- var r = yield col.insert([{a:1}, {a:2}, {a:2}]);
- assert.equal(3, r.result.n);
-
- // Modify and return the modified document
- var r = yield col.findOneAndUpdate({a:1}, {$set: {b: 1}}, {
- returnOriginal: false
- , sort: [['a',1]]
- , upsert: true
- });
- assert.equal(1, r.value.b);
-
- // Remove and return a document
- var r = yield col.findOneAndDelete({a:2});
- assert.ok(r.value.b == null);
- db.close();
-}).catch(function(err) {
- console.log(err.stack);
-});
-```
-
-The *findOneAndDelete* function is a function especially defined to help remove a document. Let's look at an example of usage.
-
-```js
-var MongoClient = require('mongodb').MongoClient,
- co = require('co'),
- assert = require('assert');
-
-co(function*() {
- // Connection URL
- var db = yield MongoClient.connect('mongodb://localhost:27017/myproject');
- console.log("Connected correctly to server");
-
- // Get the findAndModify collection
- var col = db.collection('findAndModify');
- // Insert a single document
- var r = yield col.insert([{a:1}, {a:2}, {a:2}]);
- assert.equal(3, r.result.n);
-
- // Remove a document from MongoDB and return it
- var r = yield col.findOneAndDelete({a:1}, {
- sort: [['a',1]]
- });
- assert.ok(r.value.b == null);
- db.close();
-}).catch(function(err) {
- console.log(err.stack);
-});
-```
-
-## BulkWrite
-The *bulkWrite* function allows for a simple set of bulk operations to be done in a non fluent way as in comparison to the bulk API discussed next. Let's look at an example.
-
-```js
-var MongoClient = require('mongodb').MongoClient,
- co = require('co'),
- assert = require('assert');
-
-co(function*() {
- // Connection URL
- var db = yield MongoClient.connect('mongodb://localhost:27017/myproject');
- console.log("Connected correctly to server");
-
- // Get the collection
- var col = db.collection('bulk_write');
- var r = yield col.bulkWrite([
- { insertOne: { document: { a: 1 } } }
- , { updateOne: { filter: {a:2}, update: {$set: {a:2}}, upsert:true } }
- , { updateMany: { filter: {a:2}, update: {$set: {a:2}}, upsert:true } }
- , { deleteOne: { filter: {c:1} } }
- , { deleteMany: { filter: {c:1} } }
- , { replaceOne: { filter: {c:3}, replacement: {c:4}, upsert:true}}]
- , {ordered:true, w:1});
- assert.equal(1, r.insertedCount);
- assert.equal(1, Object.keys(r.insertedIds).length);
- assert.equal(1, r.matchedCount);
- assert.equal(0, r.modifiedCount);
- assert.equal(0, r.deletedCount);
- assert.equal(2, r.upsertedCount);
- assert.equal(2, Object.keys(r.upsertedIds).length);
-
- // Ordered bulk operation
- db.close();
-}).catch(function(err) {
- console.log(err.stack);
-});
-```
-
-This covers the basic write operations. Let's have a look at the Bulk write operations next.
-
-## Bulk Write Operations
-The bulk write operations make it easy to write groups of operations together to MongoDB. There are some caveats and to get the best performance you need to be running against MongoDB *2.6* or higher that support the new write commands. Bulk operations are split into *ordered* and *unordered* bulk operations. An *ordered* bulk operation guarantees the order of execution of writes while the *unordered* bulk operation makes no assumptions about the order of execution. In the Node.js driver the *unordered* bulk operations will group operations according to type and write them in parallel. Let's have a look at how to build an ordered bulk operation.
-
-```js
-var MongoClient = require('mongodb').MongoClient,
- co = require('co'),
- assert = require('assert');
-
-co(function*() {
- // Connection URL
- var db = yield MongoClient.connect('mongodb://localhost:27017/myproject');
- console.log("Connected correctly to server");
-
- // Get the collection
- var col = db.collection('bulkops');
- // Create ordered bulk, for unordered initializeUnorderedBulkOp()
- var bulk = col.initializeOrderedBulkOp();
- // Insert 10 documents
- for(var i = 0; i < 10; i++) {
- bulk.insert({a: i});
- }
-
- // Next perform some upserts
- for(var i = 0; i < 10; i++) {
- bulk.find({b:i}).upsert().updateOne({b:1});
- }
-
- // Finally perform a remove operation
- bulk.find({b:1}).deleteOne();
-
- // Execute the bulk with a journal write concern
- var result = yield bulk.execute();
- db.close();
-}).catch(function(err) {
- console.log(err.stack);
-});
-```
-
-We will not cover the results object here as it's documented in the driver API. The Bulk API handles all the splitting of operations into multiple writes and also emulates 2.6 and higher write commands for 2.4 and earlier servers.
-
-There are some important things to keep in mind when using the bulk API and especially the *ordered* bulk API mode. The write commands are single operation type. That means they can only do insert/update and remove. If you f.ex do the following combination of operations.
-
- Insert {a:1}
- Update {a:1} to {a:1, b:1}
- Insert {a:2}
- Remove {b:1}
- Insert {a:3}
-
-This will result in the driver issuing 4 write commands to the server.
-
- Insert Command with {a:1}
- Update Command {a:1} to {a:1, b:1}
- Insert Command with {a:2}
- Remove Command with {b:1}
- Insert Command with {a:3}
-
-If you instead organize your *ordered* in the following manner.
-
- Insert {a:1}
- Insert {a:2}
- Insert {a:3}
- Update {a:1} to {a:1, b:1}
- Remove {b:1}
-
-The number of write commands issued by the driver will be.
-
- Insert Command with {a:1}, {a:2}, {a:3}
- Update Command {a:1} to {a:1, b:1}
- Remove Command with {b:1}
-
-Allowing for more efficient and faster bulk write operation.
-
-For *unordered* bulk operations this is not important as the driver sorts operations by type and executes them in parallel.
-
-This covers write operations for MongoDB. Let's look at querying for documents next.
-
-## Read Methods
-The main method for querying the database are the *find* and the *aggregate* method. In this CRUD tutorial we will focus on *find*.
-
-The *method* return a cursor that allows us to operate on the data. The *cursor* also implements the Node.js 0.10.x or higher stream interface allowing us to pipe the results to other streams.
-
-Let's look at a simple find example that materializes all the documents from a query using the toArray but limits the number of returned results to 2 documents.
-
-```js
-var MongoClient = require('mongodb').MongoClient,
- co = require('co'),
- assert = require('assert');
-
-co(function*() {
- // Connection URL
- var db = yield MongoClient.connect('mongodb://localhost:27017/myproject');
- console.log("Connected correctly to server");
-
- // Get the collection
- var col = db.collection('find');
- // Insert a single document
- var r = yield col.insertMany([{a:1}, {a:1}, {a:1}]);
- assert.equal(3, r.insertedCount);
-
- // Get first two documents that match the query
- var docs = yield col.find({a:1}).limit(2).toArray();
- assert.equal(2, docs.length);
- db.close();
-}).catch(function(err) {
- console.log(err.stack);
-});
-```
-
-Next lets take a look at the *next* method and how we can iterate over the cursor in ECMAScript 6. The new `generator` functions allow for what is arguably a much cleaner and easier to read iteration code.
-
-```js
-var MongoClient = require('mongodb').MongoClient,
- co = require('co'),
- assert = require('assert');
-
-co(function*() {
- // Connection URL
- var db = yield MongoClient.connect('mongodb://localhost:27017/myproject');
- console.log("Connected correctly to server");
-
- // Get the collection
- var col = db.collection('find');
- // Insert a single document
- var r = yield col.insertMany([{a:1}, {a:1}, {a:1}]);
- assert.equal(3, r.insertedCount);
-
- // Get the cursor
- var cursor = col.find({a:1}).limit(2);
-
- // Iterate over the cursor
- while(yield cursor.hasNext()) {
- var doc = yield cursor.next();
- console.dir(doc);
- }
-
- db.close();
-}).catch(function(err) {
- console.log(err.stack);
-});
-```
-
-## Executing Commands
-The `Db.command` method also returns a `Promise` allowing us to leverage `generators` to get clear and concise code. Below is an example calling the `buildInfo` method.
-
-```js
-var MongoClient = require('mongodb').MongoClient,
- co = require('co'),
- assert = require('assert');
-
-co(function*() {
- // Connection URL
- var db = yield MongoClient.connect('mongodb://localhost:27017/myproject');
- console.log("Connected correctly to server");
- // Use the admin database for the operation
- var adminDb = db.admin();
- // Retrive the build information using the admin command
- yield adminDb.command({buildInfo:1})
- db.close();
-}).catch(function(err) {
- console.log(err.stack);
-});
-```
diff --git a/docs/reference/content/reference/ecmascript6/index.md b/docs/reference/content/reference/ecmascript6/index.md
deleted file mode 100644
index 352c2b1d4c..0000000000
--- a/docs/reference/content/reference/ecmascript6/index.md
+++ /dev/null
@@ -1,24 +0,0 @@
-+++
-date = "2015-03-19T12:53:30-04:00"
-title = "ECMAScript 6"
-[menu.main]
- parent = "Reference"
- identifier = "ECMAScript 6"
- weight = 70
- pre = ""
-+++
-
-# ECMAScript 6
-
-ECMAScript 6 or JavaScript 6 as it's more commonly known is the new future of the Javascript language. It introduces fundamental changes in JavaScript while maintaining backward compatibility with ECMAScript 5.
-
-The MongoDB Node.js driver embraces the new JavaScript version to provide the end user with much improved functionality. We do this primarily by exposing Promises for all `async` methods without breaking backward compatibility with existing code using the driver.
-
-This section exposes how to use the MongoDB Node.js driver with ECMAScript 6, leveraging all the productivity gains you get from the new Generators.
-
-{{% note %}}
-For more information about ECMAScript 6 see the [ECMAScript 6 features](http://es6-features.org/).
-{{% /note %}}
-
-- [Connecting]({{}}): how to connect leveraging ECMAScript 6.
-- [CRUD]({{}}): perform CRUD operations leveraging ECMAScript 6.
diff --git a/docs/reference/content/reference/ecmascriptnext/connecting.md b/docs/reference/content/reference/ecmascriptnext/connecting.md
new file mode 100644
index 0000000000..4d2a3af210
--- /dev/null
+++ b/docs/reference/content/reference/ecmascriptnext/connecting.md
@@ -0,0 +1,41 @@
++++
+date = "2015-03-19T12:53:30-04:00"
+title = "Connecting"
+[menu.main]
+ parent = "ECMAScript Next"
+ identifier = "Connection"
+ weight = 60
+ pre = ""
++++
+
+# Connecting
+
+The MongoClient connection method returns a Promise if no callback is passed to it. Below is an example using the `async`/`await` commands.
+
+```js
+const MongoClient = require('mongodb').MongoClient;
+const assert = require('assert');
+
+(async function() {
+ // Connection URL
+ const url = 'mongodb://localhost:27017/myproject';
+ // Database Name
+ const dbName = 'myproject';
+ let client;
+
+ try {
+ // Use connect method to connect to the Server
+ client = await MongoClient.connect(url);
+
+ const db = client.db(dbName);
+ } catch (err) {
+ console.log(err.stack);
+ }
+
+ if (client) {
+ client.close();
+ }
+})();
+```
+
+The `MongoClient.connect` function returns a `Promise` that we then execute using the `await` keyword inside of an `async` function. If an error happens during the `MongoClient.connect` the error is caught by the `try`/`catch` and can be handled as if it were a normal Javascript error.
diff --git a/docs/reference/content/reference/ecmascriptnext/crud.md b/docs/reference/content/reference/ecmascriptnext/crud.md
new file mode 100644
index 0000000000..d6d1f76314
--- /dev/null
+++ b/docs/reference/content/reference/ecmascriptnext/crud.md
@@ -0,0 +1,522 @@
++++
+date = "2015-03-19T12:53:30-04:00"
+title = "CRUD Operations"
+[menu.main]
+ parent = "ECMAScript Next"
+ identifier = "CRUD"
+ weight = 70
+ pre = ""
++++
+
+# ECMAScript Next CRUD
+
+Let's take a look at the CRUD operations from the perspective of ESNext. In this guide we will be using the same examples as in the general CRUD specification overview but rewrite them to use the new ESNext features. For all method options refer to the main CRUD tutorial.
+
+- [CRUD]({{}}): CRUD Specification.
+
+This reference also omits methods that no longer make sense when using ESNext such as the `each` and `forEach` methods.
+
+## Inserting Documents
+The *insertOne* and *insertMany* methods exists on the *Collection* class and is used to insert documents into MongoDB. Code speaks a thousand words so let's see two simple examples of inserting documents.
+
+```js
+const MongoClient = require('mongodb').MongoClient;
+const assert = require('assert');
+
+const url = 'mongodb://localhost:27017';
+const dbName = 'myproject';
+
+(async function() {
+ let client;
+
+ try {
+ client = await MongoClient.connect(url);
+ console.log("Connected correctly to server");
+
+ const db = client.db(dbName);
+
+ // Insert a single document
+ let r = await db.collection('inserts').insertOne({a:1});
+ assert.equal(1, r.insertedCount);
+
+ // Insert multiple documents
+ r = await db.collection('inserts').insertMany([{a:2}, {a:3}]);
+ assert.equal(2, r.insertedCount);
+ } catch (err) {
+ console.log(err.stack);
+ }
+
+ // Close connection
+ client.close();
+})();
+```
+
+Let's look at a simple example where we are writing to a replicaset and we wish to ensure that we serialize a passed in function as well as have the server assign the *_id* for each document.
+
+```js
+const MongoClient = require('mongodb').MongoClient;
+const assert = require('assert');
+
+const url = 'mongodb://localhost:27017';
+const dbName = 'myproject';
+
+(async function() {
+ let client;
+
+ try {
+ client = await MongoClient.connect(url);
+ console.log("Connected correctly to server");
+
+ const db = client.db(dbName);
+
+ // Insert a single document
+ const r = await db.collection('inserts').insertOne({
+ a:1,
+ b: function() { return 'hello'; }
+ }, {
+ w: 'majority',
+ wtimeout: 10000,
+ serializeFunctions: true,
+ forceServerObjectId: true
+ }
+ );
+
+ assert.equal(1, r.insertedCount);
+ } catch (err) {
+ console.log(err.stack);
+ }
+
+ // Close connection
+ client.close();
+})();
+```
+
+That wraps up the *insert* methods. Next let's look at the *update* methods.
+
+## Updating Documents
+The *updateOne* and *updateMany* methods exists on the *Collection* class and is used to update and upsert documents into MongoDB. Let's look at a couple of usage examples.
+
+```js
+const MongoClient = require('mongodb').MongoClient;
+const assert = require('assert');
+
+const url = 'mongodb://localhost:27017';
+const dbName = 'myproject';
+
+(async function() {
+ let client;
+
+ try {
+ client = await MongoClient.connect(url);
+ console.log("Connected correctly to server");
+
+ const db = client.db(dbName);
+ let r;
+
+ // Insert a single document
+ r = await col.insertMany([{a:1}, {a:2}, {a:2}]);
+ assert.equal(3, r.insertedCount);
+
+ // Update a single document
+ r = await col.updateOne({a:1}, {$set: {b: 1}});
+ assert.equal(1, r.matchedCount);
+ assert.equal(1, r.modifiedCount);
+
+ // Update multiple documents
+ r = await col.updateMany({a:2}, {$set: {b: 1}});
+ assert.equal(2, r.matchedCount);
+ assert.equal(2, r.modifiedCount);
+
+ // Upsert a single document
+ r = await col.updateOne({a:3}, {$set: {b: 1}}, {upsert: true});
+ assert.equal(0, r.matchedCount);
+ assert.equal(1, r.upsertedCount);
+ } catch (err) {
+ console.log(err.stack);
+ }
+
+ // Close connection
+ client.close();
+})();
+```
+
+## Removing Documents
+The *deleteOne* and *deleteMany* methods exist on the *Collection* class and is used to remove documents from MongoDB. Let's look at a couple of usage examples.
+
+```js
+const MongoClient = require('mongodb').MongoClient;
+const assert = require('assert');
+
+const url = 'mongodb://localhost:27017';
+const dbName = 'myproject';
+
+(async function() {
+ let client;
+
+ try {
+ client = await MongoClient.connect(url);
+ console.log("Connected correctly to server");
+
+ const db = client.db(dbName);
+
+ // Get the removes collection
+ const col = db.collection('removes');
+ let r;
+
+ // Insert a single document
+ r = await col.insertMany([{a:1}, {a:2}, {a:2}]);
+ assert.equal(3, r.insertedCount);
+
+ // Remove a single document
+ r = await col.deleteOne({a:1});
+ assert.equal(1, r.deletedCount);
+
+ // Update multiple documents
+ r = await col.deleteMany({a:2});
+ assert.equal(2, r.deletedCount);
+ } catch (err) {
+ console.log(err.stack);
+ }
+
+ // Close connection
+ client.close();
+})();
+```
+
+## findOneAndUpdate, findOneAndDelete and findOneAndReplace
+The three methods *findOneAndUpdate*, *findOneAndDelete* and *findOneAndReplace* are special commands that allows the user to update or upsert a document and have the modified or existing document returned. It comes at a cost as the operation takes a write lock for the duration of the operation as it needs to ensure the modification is *atomic*. Let's look at *findOneAndUpdate* first using an example.
+
+```js
+const MongoClient = require('mongodb').MongoClient;
+const assert = require('assert');
+
+const url = 'mongodb://localhost:27017';
+const dbName = 'myproject';
+
+(async function() {
+ let client;
+
+ try {
+ client = await MongoClient.connect(url);
+ console.log("Connected correctly to server");
+
+ const db = client.db(dbName);
+
+ // Get the findAndModify collection
+ const col = db.collection('findAndModify');
+ let r;
+
+ // Insert a single document
+ r = await col.insert([{a:1}, {a:2}, {a:2}]);
+ assert.equal(3, r.result.n);
+
+ // Modify and return the modified document
+ r = await col.findOneAndUpdate({a:1}, {$set: {b: 1}}, {
+ returnOriginal: false,
+ sort: [['a',1]],
+ upsert: true
+ });
+ assert.equal(1, r.value.b);
+
+ // Remove and return a document
+ r = await col.findOneAndDelete({a:2});
+ assert.ok(r.value.b == null);
+ } catch (err) {
+ console.log(err.stack);
+ }
+
+ // Close connection
+ client.close();
+})();
+```
+
+The *findOneAndDelete* function is a function especially defined to help remove a document. Let's look at an example of usage.
+
+```js
+const MongoClient = require('mongodb').MongoClient;
+const assert = require('assert');
+
+const url = 'mongodb://localhost:27017';
+const dbName = 'myproject';
+
+(async function() {
+ let client;
+
+ try {
+ client = await MongoClient.connect(url);
+ console.log("Connected correctly to server");
+
+ const db = client.db(dbName);
+
+ // Get the findAndModify collection
+ const col = db.collection('findAndModify');
+ let r;
+
+ // Insert a single document
+ r = await col.insert([{a:1}, {a:2}, {a:2}]);
+ assert.equal(3, r.result.n);
+
+ // Remove a document from MongoDB and return it
+ r = await col.findOneAndDelete({a:1}, {sort: [['a',1]]});
+ assert.ok(r.value.b == null);
+ } catch (err) {
+ console.log(err.stack);
+ }
+
+ // Close connection
+ client.close();
+})();
+```
+
+## BulkWrite
+The *bulkWrite* function allows for a simple set of bulk operations to be done in a non fluent way as in comparison to the bulk API discussed next. Let's look at an example.
+
+```js
+const MongoClient = require('mongodb').MongoClient;
+const assert = require('assert');
+
+const url = 'mongodb://localhost:27017';
+const dbName = 'myproject';
+
+(async function() {
+ let client;
+
+ try {
+ client = await MongoClient.connect(url);
+ console.log("Connected correctly to server");
+
+ const db = client.db(dbName);
+
+ // Get the collection
+ const col = db.collection('bulk_write');
+
+ const r = await col.bulkWrite([
+ { insertOne: { document: { a: 1 } } },
+ { updateOne: { filter: {a:2}, update: {$set: {a:2}}, upsert:true } },
+ { updateMany: { filter: {a:2}, update: {$set: {a:2}}, upsert:true } },
+ { deleteOne: { filter: {c:1} } },
+ { deleteMany: { filter: {c:1} } },
+ { replaceOne: { filter: {c:3}, replacement: {c:4}, upsert:true}}
+ ],
+ {ordered:true, w:1}
+ );
+ assert.equal(1, r.insertedCount);
+ assert.equal(1, Object.keys(r.insertedIds).length);
+ assert.equal(1, r.matchedCount);
+ assert.equal(0, r.modifiedCount);
+ assert.equal(0, r.deletedCount);
+ assert.equal(2, r.upsertedCount);
+ assert.equal(2, Object.keys(r.upsertedIds).length);
+ } catch (err) {
+ console.log(err.stack);
+ }
+
+ // Close connection
+ client.close();
+})();
+```
+
+This covers the basic write operations. Let's have a look at the Bulk write operations next.
+
+## Bulk Write Operations
+The bulk write operations make it easy to write groups of operations together to MongoDB. There are some caveats and to get the best performance you need to be running against MongoDB *2.6* or higher that support the new write commands. Bulk operations are split into *ordered* and *unordered* bulk operations. An *ordered* bulk operation guarantees the order of execution of writes while the *unordered* bulk operation makes no assumptions about the order of execution. In the Node.js driver the *unordered* bulk operations will group operations according to type and write them in parallel. Let's have a look at how to build an ordered bulk operation.
+
+```js
+const MongoClient = require('mongodb').MongoClient;
+const assert = require('assert');
+
+const url = 'mongodb://localhost:27017';
+const dbName = 'myproject';
+
+(async function() {
+ let client;
+
+ try {
+ client = await MongoClient.connect(url);
+ console.log("Connected correctly to server");
+
+ const db = client.db(dbName);
+
+ // Get the collection
+ const col = db.collection('bulkops');
+
+ // Create ordered bulk, for unordered initializeUnorderedBulkOp()
+ const bulk = col.initializeOrderedBulkOp();
+ // Insert 10 documents
+ for(let i = 0; i < 10; i++) {
+ bulk.insert({a: i});
+ }
+
+ // Next perform some upserts
+ for(let i = 0; i < 10; i++) {
+ bulk.find({b:i}).upsert().updateOne({b:1});
+ }
+
+ // Finally perform a remove operation
+ bulk.find({b:1}).deleteOne();
+
+ // Execute the bulk with a journal write concern
+ const result = await bulk.execute();
+ } catch (err) {
+ console.log(err.stack);
+ }
+
+ // Close connection
+ client.close();
+})();
+```
+
+We will not cover the results object here as it's documented in the driver API. The Bulk API handles all the splitting of operations into multiple writes.
+
+There are some important things to keep in mind when using the bulk API and especially the *ordered* bulk API mode. The write commands are single operation type. That means they can only do insert/update and remove. If you f.ex do the following combination of operations.
+
+ Insert {a:1}
+ Update {a:1} to {a:1, b:1}
+ Insert {a:2}
+ Remove {b:1}
+ Insert {a:3}
+
+This will result in the driver issuing 4 write commands to the server.
+
+ Insert Command with {a:1}
+ Update Command {a:1} to {a:1, b:1}
+ Insert Command with {a:2}
+ Remove Command with {b:1}
+ Insert Command with {a:3}
+
+If you instead organize your *ordered* in the following manner.
+
+ Insert {a:1}
+ Insert {a:2}
+ Insert {a:3}
+ Update {a:1} to {a:1, b:1}
+ Remove {b:1}
+
+The number of write commands issued by the driver will be.
+
+ Insert Command with {a:1}, {a:2}, {a:3}
+ Update Command {a:1} to {a:1, b:1}
+ Remove Command with {b:1}
+
+Allowing for more efficient and faster bulk write operation.
+
+For *unordered* bulk operations this is not important as the driver sorts operations by type and executes them in parallel.
+
+This covers write operations for MongoDB. Let's look at querying for documents next.
+
+## Read Methods
+The main method for querying the database are the *find* and the *aggregate* method. In this CRUD tutorial we will focus on *find*.
+
+The *method* return a cursor that allows us to operate on the data. The *cursor* also implements the Node.js 0.10.x or higher stream interface allowing us to pipe the results to other streams.
+
+Let's look at a simple find example that materializes all the documents from a query using the toArray but limits the number of returned results to 2 documents.
+
+```js
+const MongoClient = require('mongodb').MongoClient;
+const assert = require('assert');
+
+const url = 'mongodb://localhost:27017';
+const dbName = 'myproject';
+
+(async function() {
+ let client;
+
+ try {
+ client = await MongoClient.connect(url);
+ console.log("Connected correctly to server");
+
+ const db = client.db(dbName);
+
+ // Get the collection
+ const col = db.collection('find');
+
+ // Insert a single document
+ const r = await col.insertMany([{a:1}, {a:1}, {a:1}]);
+ assert.equal(3, r.insertedCount);
+
+ // Get first two documents that match the query
+ const docs = await col.find({a:1}).limit(2).toArray();
+ assert.equal(2, docs.length);
+ } catch (err) {
+ console.log(err.stack);
+ }
+
+ // Close connection
+ client.close();
+})();
+```
+
+Next lets take a look at the *next* method and how we can iterate over the cursor in ECMAScript 6. The new `async`/`await` commands allow for what is arguably a much cleaner and easier to read iteration code.
+
+```js
+const MongoClient = require('mongodb').MongoClient;
+const assert = require('assert');
+
+const url = 'mongodb://localhost:27017';
+const dbName = 'myproject';
+
+(async function() {
+ let client;
+
+ try {
+ client = await MongoClient.connect(url);
+ console.log("Connected correctly to server");
+
+ const db = client.db(dbName);
+
+ // Get the collection
+ const col = db.collection('find');
+
+ // Insert a single document
+ const r = await col.insertMany([{a:1}, {a:1}, {a:1}]);
+ assert.equal(3, r.insertedCount);
+
+ // Get the cursor
+ const cursor = col.find({a:1}).limit(2);
+
+ // Iterate over the cursor
+ while(await cursor.hasNext()) {
+ const doc = await cursor.next();
+ console.dir(doc);
+ }
+ } catch (err) {
+ console.log(err.stack);
+ }
+
+ // Close connection
+ client.close();
+})();
+```
+
+## Executing Commands
+The `Db.command` method also returns a `Promise` allowing us to leverage `async`/`await` to get clear and concise code. Below is an example calling the `buildInfo` method.
+
+```js
+const MongoClient = require('mongodb').MongoClient;
+const assert = require('assert');
+
+const url = 'mongodb://localhost:27017';
+const dbName = 'myproject';
+
+(async function() {
+ let client;
+
+ try {
+ client = await MongoClient.connect(url);
+ console.log("Connected correctly to server");
+
+ const db = client.db(dbName);
+
+ // Use the admin database for the operation
+ const adminDb = db.admin();
+
+ // Retrive the build information using the admin command
+ await adminDb.command({buildInfo:1})
+ } catch (err) {
+ console.log(err.stack);
+ }
+
+ // Close connection
+ client.close();
+})();
+```
diff --git a/docs/reference/content/reference/ecmascriptnext/index.md b/docs/reference/content/reference/ecmascriptnext/index.md
new file mode 100644
index 0000000000..e1a2824dd4
--- /dev/null
+++ b/docs/reference/content/reference/ecmascriptnext/index.md
@@ -0,0 +1,24 @@
++++
+date = "2015-03-19T12:53:30-04:00"
+title = "ECMAScript Next"
+[menu.main]
+ parent = "Reference"
+ identifier = "ECMAScript Next"
+ weight = 70
+ pre = ""
++++
+
+# ECMAScript Next
+
+ECMAScript Next (also know as ESNext, ES2015, ES6, and many other names) is the new future of the Javascript language. It introduces fundamental changes in JavaScript while maintaining backward compatibility with ECMAScript 5.
+
+The MongoDB Node.js driver embraces modern JavaScript by optionally returning Promises from all `async` methods.
+
+This section exposes how to use the MongoDB Node.js driver with ESNext, leveraging all the productivity gains you get from the new Javascript.
+
+{{% note %}}
+For more information about ECMAScript Next see the [ECMAScript 6 features](http://es6-features.org/).
+{{% /note %}}
+
+- [Connecting]({{}}): how to connect leveraging ESNext.
+- [CRUD]({{}}): perform CRUD operations leveraging ESNext.
diff --git a/docs/reference/content/reference/faq/index.md b/docs/reference/content/reference/faq/index.md
index 641ce3ecba..65d130cf04 100644
--- a/docs/reference/content/reference/faq/index.md
+++ b/docs/reference/content/reference/faq/index.md
@@ -111,7 +111,7 @@ This can occur if the connection pool is too large.
```js
MongoClient.connect('mongodb://localhost:27017/test?maxPoolSize=5000',
- function(err, db) {
+ function(err, client) {
// connection
});
```
diff --git a/docs/reference/content/reference/management/apm.md b/docs/reference/content/reference/management/apm.md
index 813b787518..29b6d8451b 100644
--- a/docs/reference/content/reference/management/apm.md
+++ b/docs/reference/content/reference/management/apm.md
@@ -22,7 +22,7 @@ The following code example hooks into all the available features
of the APM API.
```js
-var listener = require('mongodb').instrument({
+const listener = require('mongodb').instrument({
operationIdGenerator: {
operationId: 1,
@@ -274,7 +274,7 @@ APM experience and performance breakdown. Below is a simple
`operationIdGenerator` example.
```js
-var generator = {
+const generator = {
operationId: 1,
next: function() {
@@ -292,7 +292,7 @@ timestamp` and `duration` calculates the total operation duration
between the `start` and `end` time. Below is a simple generator example.
```js
-var generator = {
+const generator = {
current: function() {
return new Date().getTime();
},
@@ -443,21 +443,21 @@ The available options are:
Below is a very basic instrumentation example.
```js
-var listener = require('../..').instrument(function(err, instrumentations) {
+const listener = require('../..').instrument(function(err, instrumentations) {
instrumentations.forEach(function(obj) {
- var object = obj.obj;
+ const object = obj.obj;
// Iterate over all the methods that are just callback with no return
obj.instrumentations.forEach(function(instr) {
- var options = instr.options;
+ const options = instr.options;
if(options.callback
&& !options.returns && !options.static) {
// Method name
instr.methods.forEach(function(method) {
- var applyMethod = function(_method) {
- var func = object.prototype[_method];
+ function applyMethod(_method) {
+ const func = object.prototype[_method];
overrides.push({
obj: object.prototype, method: _method, func: func
@@ -466,7 +466,7 @@ var listener = require('../..').instrument(function(err, instrumentations) {
object.prototype[_method] = function() {
if(!methodsCalled[_method]) methodsCalled[_method] = 0;
methodsCalled[_method] = methodsCalled[_method] + 1;
- var args = Array.prototype.slice.call(arguments, 0);
+ const args = Array.prototype.slice.call(arguments, 0);
func.apply(this, args);
}
}
diff --git a/docs/reference/content/reference/management/logging.md b/docs/reference/content/reference/management/logging.md
index c98e257a20..eb91dd260d 100644
--- a/docs/reference/content/reference/management/logging.md
+++ b/docs/reference/content/reference/management/logging.md
@@ -19,24 +19,29 @@ The driver allows logging at three different levels: `debug`,
The following example demonstrates how to set the logger to `debug`.
```js
-var MongoClient = require('mongodb').MongoClient
- , Logger = require('mongodb').Logger
- , assert = require('assert');
+const MongoClient = require('mongodb').MongoClient;
+const Logger = require('mongodb').Logger;
+const assert = require('assert');
// Connection URL
-var url = 'mongodb://localhost:27017/myproject';
+const url = 'mongodb://localhost:27017';
+// Database Name
+const dbName = 'myprojeect';
+
// Use connect method to connect to the Server
-MongoClient.connect(url, function(err, db) {
+MongoClient.connect(url, function(err, client) {
assert.equal(null, err);
console.log("Connected correctly to server");
// Set debug level
Logger.setLevel('debug');
+ const db = client.db(dbName);
+
// Execute command {ismaster:true} against db
db.command({ismaster:true}, function(err, d) {
assert.equal(null, err);
- db.close();
+ client.close();
});
});
```
@@ -47,14 +52,17 @@ You can set the Logger to only log specific class names. The following example
demonstrates how to log only the `Db` class.
```js
-var MongoClient = require('mongodb').MongoClient
- , Logger = require('mongodb').Logger
- , assert = require('assert');
+const MongoClient = require('mongodb').MongoClient;
+const Logger = require('mongodb').Logger;
+const assert = require('assert');
// Connection URL
-var url = 'mongodb://localhost:27017/myproject';
+const url = 'mongodb://localhost:27017';
+// Database Name
+const dbName = 'myprojeect';
+
// Use connect method to connect to the Server
-MongoClient.connect(url, function(err, db) {
+MongoClient.connect(url, function(err, client) {
assert.equal(null, err);
console.log("Connected correctly to server");
@@ -63,10 +71,12 @@ MongoClient.connect(url, function(err, db) {
// Only log statements on 'Db' class
Logger.filter('class', ['Db']);
+ const db = client.db(dbName);
+
// Execute command {ismaster:true} against db
db.command({ismaster:true}, function(err, d) {
assert.equal(null, err);
- db.close();
+ client.close();
});
});
```
@@ -85,19 +95,23 @@ Driver classes available for filtering:
You can add your own classes to the logger by creating your own logger instances.
```js
-var Logger = require('mongodb').Logger
- , assert = require('assert');
+const Logger = require('mongodb').Logger;
+const assert = require('assert');
-var A = function() {
- var logger = Logger('A', options);
+class A {
+ constructor() {
+ this.logger = new Logger('A');
+ }
- this.do = function() {
- if(logger.isInfo()) logger.info('logging A', {});
+ do() {
+ if (this.logger.isInfo()) {
+ this.logger.info('logging A', {});
+ }
}
}
// Execute A
-var a = new A();
+const a = new A();
a.do();
```
@@ -106,14 +120,17 @@ a.do();
The following example demonstrates how to define a custom logger.
```js
-var MongoClient = require('mongodb').MongoClient
- , Logger = require('mongodb').Logger
- , assert = require('assert');
+const MongoClient = require('mongodb').MongoClient;
+const Logger = require('mongodb').Logger;
+const assert = require('assert');
// Connection URL
-var url = 'mongodb://localhost:27017/myproject';
+const url = 'mongodb://localhost:27017';
+// Database Name
+const dbName = 'myprojeect';
+
// Use connect method to connect to the Server
-MongoClient.connect(url, function(err, db) {
+MongoClient.connect(url, function(err, client) {
assert.equal(null, err);
console.log("Connected correctly to server");
@@ -125,10 +142,12 @@ MongoClient.connect(url, function(err, db) {
console.log(msg, context);
});
+ const db = client.db(dbName);
+
// Execute command {ismaster:true} against db
db.command({ismaster:true}, function(err, d) {
assert.equal(null, err);
- db.close();
+ client.close();
});
});
```
diff --git a/docs/reference/content/reference/management/sdam-monitoring.md b/docs/reference/content/reference/management/sdam-monitoring.md
index 294a6119e0..79f2ddbca3 100644
--- a/docs/reference/content/reference/management/sdam-monitoring.md
+++ b/docs/reference/content/reference/management/sdam-monitoring.md
@@ -35,10 +35,10 @@ joining or leaving a replica set.
The following example demonstrates how to connect to a replica set and monitor all the events that are emitted by the replica set topology.
```js
-var MongoClient = require('mongodb').MongoClient;
+const MongoClient = require('mongodb').MongoClient;
-var url = 'mongodb://localhost:31000,localhost:31001/db?replicaSet=rs';
-var client = new MongoClient();
+const url = 'mongodb://localhost:31000,localhost:31001/?replicaSet=rs';
+const client = new MongoClient();
client.on('serverDescriptionChanged', function(event) {
console.log('received serverDescriptionChanged');
@@ -85,7 +85,7 @@ client.on('topologyDescriptionChanged', function(event) {
console.log(JSON.stringify(event, null, 2));
});
-client.connect(url, function(err, db) {
+client.connect(url, function(err, client) {
if(err) throw err;
});
```
diff --git a/docs/reference/content/reference/pool/index.md b/docs/reference/content/reference/pool/index.md
index 25c9156efa..e60616c793 100644
--- a/docs/reference/content/reference/pool/index.md
+++ b/docs/reference/content/reference/pool/index.md
@@ -10,7 +10,7 @@ title = "Pool Design"
# Driver Pool Design
-The 2.0 series of the mongodb-core module introduces a newly re-designed pool that will grow and contract based on the usage pattern. This reference outlines how the growing/shrinking of the pool works, how authentication is handled and how operations are executed.
+The 2.0 series of the mongodb-core module introduced a newly re-designed pool that will grow and contract based on the usage pattern. This reference outlines how the growing/shrinking of the pool works, how authentication is handled and how operations are executed.
Operations are executed using a work-queue. That means the Pool is responsible for scheduling the execution of operations on connections. The benefit of this is that one avoids slow operations holding up fast operations as long as the following holds true.