diff --git a/lib/admin.js b/lib/admin.js index 01c96ffc7a..21387cc7b3 100644 --- a/lib/admin.js +++ b/lib/admin.js @@ -11,20 +11,23 @@ var toError = require('./utils').toError, * * **ADMIN Cannot directly be instantiated** * @example - * var MongoClient = require('mongodb').MongoClient, - * test = require('assert'); + * const MongoClient = require('mongodb').MongoClient; + * const test = require('assert'); * // Connection url - * var url = 'mongodb://localhost:27017/test'; + * const url = 'mongodb://localhost:27017'; + * // Database Name + * const dbName = 'test'; + * * // Connect using MongoClient - * MongoClient.connect(url, function(err, db) { + * MongoClient.connect(url, function(err, client) { * // Use the admin database for the operation - * var adminDb = db.admin(); + * const adminDb = client.db(dbName).admin(); * * // List all the available databases * adminDb.listDatabases(function(err, dbs) { * test.equal(null, err); * test.ok(dbs.databases.length > 0); - * db.close(); + * client.close(); * }); * }); */ diff --git a/lib/aggregation_cursor.js b/lib/aggregation_cursor.js index eb1b20ea22..8ad940bdd4 100644 --- a/lib/aggregation_cursor.js +++ b/lib/aggregation_cursor.js @@ -9,19 +9,21 @@ var inherits = require('util').inherits, /** * @fileOverview The **AggregationCursor** class is an internal class that embodies an aggregation cursor on MongoDB * allowing for iteration over the results returned from the underlying query. It supports - * one by one document iteration, conversion to an array or can be iterated as a Node 0.10.X + * one by one document iteration, conversion to an array or can be iterated as a Node 4.X * or higher stream * * **AGGREGATIONCURSOR Cannot directly be instantiated** * @example - * var MongoClient = require('mongodb').MongoClient, - * test = require('assert'); + * const MongoClient = require('mongodb').MongoClient; + * const test = require('assert'); * // Connection url - * var url = 'mongodb://localhost:27017/test'; + * const url = 'mongodb://localhost:27017'; + * // Database Name + * const dbName = 'test'; * // Connect using MongoClient - * MongoClient.connect(url, function(err, db) { + * MongoClient.connect(url, function(err, client) { * // Create a collection we want to drop later - * var col = db.collection('createIndexExample1'); + * const col = client.db(dbName).collection('createIndexExample1'); * // Insert a bunch of documents * col.insert([{a:1, b:1} * , {a:2, b:2}, {a:3, b:3} @@ -31,7 +33,7 @@ var inherits = require('util').inherits, * col.aggregation({}, {cursor: {}}).toArray(function(err, items) { * test.equal(null, err); * test.equal(4, items.length); - * db.close(); + * client.close(); * }); * }); * }); diff --git a/lib/collection.js b/lib/collection.js index e79f9cfafc..2e3f36a6ce 100644 --- a/lib/collection.js +++ b/lib/collection.js @@ -30,19 +30,21 @@ var checkCollectionName = require('./utils').checkCollectionName, * * **COLLECTION Cannot directly be instantiated** * @example - * var MongoClient = require('mongodb').MongoClient, - * test = require('assert'); + * const MongoClient = require('mongodb').MongoClient; + * const test = require('assert'); * // Connection url - * var url = 'mongodb://localhost:27017/test'; + * const url = 'mongodb://localhost:27017'; + * // Database Name + * const dbName = 'test'; * // Connect using MongoClient - * MongoClient.connect(url, function(err, db) { + * MongoClient.connect(url, function(err, client) { * // Create a collection we want to drop later - * var col = db.collection('createIndexExample1'); + * const col = client.db(dbName).collection('createIndexExample1'); * // Show that duplicate records got dropped * col.find({}).toArray(function(err, items) { * test.equal(null, err); * test.equal(4, items.length); - * db.close(); + * client.close(); * }); * }); */ diff --git a/lib/command_cursor.js b/lib/command_cursor.js index 48c3708754..481cea0a4b 100644 --- a/lib/command_cursor.js +++ b/lib/command_cursor.js @@ -15,24 +15,25 @@ var inherits = require('util').inherits, * * **CommandCursor Cannot directly be instantiated** * @example - * var MongoClient = require('mongodb').MongoClient, - * test = require('assert'); + * const MongoClient = require('mongodb').MongoClient; + * const test = require('assert'); * // Connection url - * var url = 'mongodb://localhost:27017/test'; + * const url = 'mongodb://localhost:27017'; + * // Database Name + * const dbName = 'test'; * // Connect using MongoClient - * MongoClient.connect(url, function(err, db) { + * MongoClient.connect(url, function(err, client) { * // Create a collection we want to drop later - * var col = db.collection('listCollectionsExample1'); + * const col = client.db(dbName).collection('listCollectionsExample1'); * // Insert a bunch of documents * col.insert([{a:1, b:1} * , {a:2, b:2}, {a:3, b:3} * , {a:4, b:4}], {w:1}, function(err, result) { * test.equal(null, err); - * * // List the database collections available * db.listCollections().toArray(function(err, items) { * test.equal(null, err); - * db.close(); + * client.close(); * }); * }); * }); diff --git a/lib/cursor.js b/lib/cursor.js index 97bf15a560..009fd0b07f 100644 --- a/lib/cursor.js +++ b/lib/cursor.js @@ -15,30 +15,31 @@ var inherits = require('util').inherits, /** * @fileOverview The **Cursor** class is an internal class that embodies a cursor on MongoDB * allowing for iteration over the results returned from the underlying query. It supports - * one by one document iteration, conversion to an array or can be iterated as a Node 0.10.X + * one by one document iteration, conversion to an array or can be iterated as a Node 4.X * or higher stream * * **CURSORS Cannot directly be instantiated** * @example - * var MongoClient = require('mongodb').MongoClient, - * test = require('assert'); + * const MongoClient = require('mongodb').MongoClient; + * const test = require('assert'); * // Connection url - * var url = 'mongodb://localhost:27017/test'; + * const url = 'mongodb://localhost:27017'; + * // Database Name + * const dbName = 'test'; * // Connect using MongoClient - * MongoClient.connect(url, function(err, db) { + * MongoClient.connect(url, function(err, client) { * // Create a collection we want to drop later - * var col = db.collection('createIndexExample1'); + * const col = client.db(dbName).collection('createIndexExample1'); * // Insert a bunch of documents * col.insert([{a:1, b:1} * , {a:2, b:2}, {a:3, b:3} * , {a:4, b:4}], {w:1}, function(err, result) { * test.equal(null, err); - * * // Show that duplicate records got dropped * col.find({}).toArray(function(err, items) { * test.equal(null, err); * test.equal(4, items.length); - * db.close(); + * client.close(); * }); * }); * }); diff --git a/lib/db.js b/lib/db.js index 374dbc5e3c..e3abadc9d6 100644 --- a/lib/db.js +++ b/lib/db.js @@ -65,15 +65,17 @@ var illegalCommandFields = [ * @fileOverview The **Db** class is a class that represents a MongoDB Database. * * @example - * var MongoClient = require('mongodb').MongoClient, - * test = require('assert'); + * const MongoClient = require('mongodb').MongoClient; + * const test = require('assert'); * // Connection url - * var url = 'mongodb://localhost:27017/test'; + * const url = 'mongodb://localhost:27017'; + * // Database Name + * const dbName = 'test'; * // Connect using MongoClient * MongoClient.connect(url, function(err, client) { * // Get an additional db - * var testDb = client.db('test'); - * db.close(); + * const testDb = client.db('test'); + * client.close(); * }); */ diff --git a/lib/gridfs/grid_store.js b/lib/gridfs/grid_store.js index 81ebc0eb02..b80d7cfaaf 100644 --- a/lib/gridfs/grid_store.js +++ b/lib/gridfs/grid_store.js @@ -9,24 +9,25 @@ * found here. * * @example - * var MongoClient = require('mongodb').MongoClient, - * GridStore = require('mongodb').GridStore, - * ObjectID = require('mongodb').ObjectID, - * test = require('assert'); - * + * const MongoClient = require('mongodb').MongoClient; + * const GridStore = require('mongodb').GridStore; + * const ObjectID = require('mongodb').ObjectID; + * const test = require('assert'); * // Connection url - * var url = 'mongodb://localhost:27017/test'; + * const url = 'mongodb://localhost:27017'; + * // Database Name + * const dbName = 'test'; * // Connect using MongoClient - * MongoClient.connect(url, function(err, db) { - * var gridStore = new GridStore(db, null, "w"); + * MongoClient.connect(url, function(err, client) { + * const db = client.db(dbName); + * const gridStore = new GridStore(db, null, "w"); * gridStore.open(function(err, gridStore) { * gridStore.write("hello world!", function(err, gridStore) { * gridStore.close(function(err, result) { - * * // Let's read the file using object Id * GridStore.read(db, result._id, function(err, data) { * test.equal('hello world!', data); - * db.close(); + * client.close(); * test.done(); * }); * }); diff --git a/lib/mongo_client.js b/lib/mongo_client.js index 5bd325693e..8ace70d2da 100644 --- a/lib/mongo_client.js +++ b/lib/mongo_client.js @@ -23,14 +23,16 @@ var parse = require('./url_parser'), * @fileOverview The **MongoClient** class is a class that allows for making Connections to MongoDB. * * @example - * var MongoClient = require('mongodb').MongoClient, - * test = require('assert'); + * const MongoClient = require('mongodb').MongoClient; + * const test = require('assert'); * // Connection url - * var url = 'mongodb://localhost:27017/test'; + * const url = 'mongodb://localhost:27017'; + * // Database Name + * const dbName = 'test'; * // Connect using MongoClient - * MongoClient.connect(url, function(err, db) { - * // Get an additional db - * db.close(); + * MongoClient.connect(url, function(err, client) { + * const db = client.db(dbName); + * client.close(); * }); */ var validOptionNames = [ diff --git a/lib/topologies/mongos.js b/lib/topologies/mongos.js index 52d08f101b..ae8443264f 100644 --- a/lib/topologies/mongos.js +++ b/lib/topologies/mongos.js @@ -21,18 +21,6 @@ var ServerCapabilities = require('./topology_base').ServerCapabilities, * used to construct connections. * * **Mongos Should not be used, use MongoClient.connect** - * @example - * var Db = require('mongodb').Db, - * Mongos = require('mongodb').Mongos, - * Server = require('mongodb').Server, - * test = require('assert'); - * // Connect using Mongos - * var server = new Server('localhost', 27017); - * var db = new Db('test', new Mongos([server])); - * db.open(function(err, db) { - * // Get an additional db - * db.close(); - * }); */ // Allowed parameters diff --git a/lib/topologies/replset.js b/lib/topologies/replset.js index ee584b7276..e01ca172f6 100644 --- a/lib/topologies/replset.js +++ b/lib/topologies/replset.js @@ -21,18 +21,6 @@ var Server = require('./server'), * used to construct connections. * * **ReplSet Should not be used, use MongoClient.connect** - * @example - * var Db = require('mongodb').Db, - * ReplSet = require('mongodb').ReplSet, - * Server = require('mongodb').Server, - * test = require('assert'); - * // Connect using ReplSet - * var server = new Server('localhost', 27017); - * var db = new Db('test', new ReplSet([server])); - * db.open(function(err, db) { - * // Get an additional db - * db.close(); - * }); */ // Allowed parameters diff --git a/lib/topologies/server.js b/lib/topologies/server.js index 1c2985294d..6f771f09f2 100644 --- a/lib/topologies/server.js +++ b/lib/topologies/server.js @@ -20,16 +20,6 @@ var CServer = require('mongodb-core').Server, * used to construct connections. * * **Server Should not be used, use MongoClient.connect** - * @example - * var Db = require('mongodb').Db, - * Server = require('mongodb').Server, - * test = require('assert'); - * // Connect using single Server - * var db = new Db('test', new Server('localhost', 27017);); - * db.open(function(err, db) { - * // Get an additional db - * db.close(); - * }); */ // Allowed parameters