Skip to content

Commit a5d0f1d

Browse files
author
Sophie Saskin
authoredAug 1, 2018
feat(deprecation): wrap deprecated functions
Wraps deprecated functions with deprecatedOptions or util.deprecate. Fixes Node-1430
1 parent 4f907a0 commit a5d0f1d

File tree

3 files changed

+195
-178
lines changed

3 files changed

+195
-178
lines changed
 

‎lib/collection.js

+172-160
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
const deprecate = require('util').deprecate;
4+
const deprecateOptions = require('./utils').deprecateOptions;
45
const checkCollectionName = require('./utils').checkCollectionName;
56
const ObjectID = require('mongodb-core').BSON.ObjectID;
67
const AggregationCursor = require('./aggregation_cursor');
@@ -237,7 +238,7 @@ Object.defineProperty(Collection.prototype, 'hint', {
237238
}
238239
});
239240

240-
const DEPRECATED_FIND_OPTIONS = ['maxScan', 'snapshot'];
241+
const DEPRECATED_FIND_OPTIONS = ['maxScan', 'fields', 'snapshot'];
241242

242243
/**
243244
* Creates a cursor for a query that can be used to iterate over results from MongoDB
@@ -273,163 +274,163 @@ const DEPRECATED_FIND_OPTIONS = ['maxScan', 'snapshot'];
273274
* @throws {MongoError}
274275
* @return {Cursor}
275276
*/
276-
Collection.prototype.find = function(query, options, callback) {
277-
if (typeof callback === 'object') {
278-
// TODO(MAJOR): throw in the future
279-
console.warn('Third parameter to `find()` must be a callback or undefined');
280-
}
281-
282-
let selector = query;
283-
// figuring out arguments
284-
if (typeof callback !== 'function') {
285-
if (typeof options === 'function') {
286-
callback = options;
287-
options = undefined;
288-
} else if (options == null) {
289-
callback = typeof selector === 'function' ? selector : undefined;
290-
selector = typeof selector === 'object' ? selector : undefined;
277+
Collection.prototype.find = deprecateOptions(
278+
{
279+
name: 'collection.find',
280+
deprecatedOptions: DEPRECATED_FIND_OPTIONS,
281+
optionsIndex: 1
282+
},
283+
function(query, options, callback) {
284+
if (typeof callback === 'object') {
285+
// TODO(MAJOR): throw in the future
286+
console.warn('Third parameter to `find()` must be a callback or undefined');
291287
}
292-
}
293288

294-
// Ensure selector is not null
295-
selector = selector == null ? {} : selector;
296-
// Validate correctness off the selector
297-
const object = selector;
298-
if (Buffer.isBuffer(object)) {
299-
const object_size = object[0] | (object[1] << 8) | (object[2] << 16) | (object[3] << 24);
300-
if (object_size !== object.length) {
301-
const error = new Error(
302-
'query selector raw message size does not match message header size [' +
303-
object.length +
304-
'] != [' +
305-
object_size +
306-
']'
307-
);
308-
error.name = 'MongoError';
309-
throw error;
289+
let selector = query;
290+
// figuring out arguments
291+
if (typeof callback !== 'function') {
292+
if (typeof options === 'function') {
293+
callback = options;
294+
options = undefined;
295+
} else if (options == null) {
296+
callback = typeof selector === 'function' ? selector : undefined;
297+
selector = typeof selector === 'object' ? selector : undefined;
298+
}
310299
}
311-
}
312300

313-
// Check special case where we are using an objectId
314-
if (selector != null && selector._bsontype === 'ObjectID') {
315-
selector = { _id: selector };
316-
}
301+
// Ensure selector is not null
302+
selector = selector == null ? {} : selector;
303+
// Validate correctness off the selector
304+
const object = selector;
305+
if (Buffer.isBuffer(object)) {
306+
const object_size = object[0] | (object[1] << 8) | (object[2] << 16) | (object[3] << 24);
307+
if (object_size !== object.length) {
308+
const error = new Error(
309+
'query selector raw message size does not match message header size [' +
310+
object.length +
311+
'] != [' +
312+
object_size +
313+
']'
314+
);
315+
error.name = 'MongoError';
316+
throw error;
317+
}
318+
}
317319

318-
if (!options) options = {};
320+
// Check special case where we are using an objectId
321+
if (selector != null && selector._bsontype === 'ObjectID') {
322+
selector = { _id: selector };
323+
}
319324

320-
let projection = options.projection || options.fields;
325+
if (!options) options = {};
321326

322-
if (projection && !Buffer.isBuffer(projection) && Array.isArray(projection)) {
323-
projection = projection.length
324-
? projection.reduce((result, field) => {
325-
result[field] = 1;
326-
return result;
327-
}, {})
328-
: { _id: 1 };
329-
}
327+
let projection = options.projection || options.fields;
330328

331-
// Make a shallow copy of options
332-
let newOptions = Object.assign({}, options);
333-
334-
// Make a shallow copy of the collection options
335-
for (let key in this.s.options) {
336-
if (mergeKeys.indexOf(key) !== -1) {
337-
newOptions[key] = this.s.options[key];
329+
if (projection && !Buffer.isBuffer(projection) && Array.isArray(projection)) {
330+
projection = projection.length
331+
? projection.reduce((result, field) => {
332+
result[field] = 1;
333+
return result;
334+
}, {})
335+
: { _id: 1 };
338336
}
339-
}
340-
341-
// Unpack options
342-
newOptions.skip = options.skip ? options.skip : 0;
343-
newOptions.limit = options.limit ? options.limit : 0;
344-
newOptions.raw = typeof options.raw === 'boolean' ? options.raw : this.s.raw;
345-
newOptions.hint = options.hint != null ? normalizeHintField(options.hint) : this.s.collectionHint;
346-
newOptions.timeout = typeof options.timeout === 'undefined' ? undefined : options.timeout;
347-
// // If we have overridden slaveOk otherwise use the default db setting
348-
newOptions.slaveOk = options.slaveOk != null ? options.slaveOk : this.s.db.slaveOk;
349-
350-
// Add read preference if needed
351-
newOptions.readPreference = resolveReadPreference(newOptions, {
352-
db: this.s.db,
353-
collection: this
354-
});
355337

356-
// Set slave ok to true if read preference different from primary
357-
if (
358-
newOptions.readPreference != null &&
359-
(newOptions.readPreference !== 'primary' || newOptions.readPreference.mode !== 'primary')
360-
) {
361-
newOptions.slaveOk = true;
362-
}
338+
// Make a shallow copy of options
339+
let newOptions = Object.assign({}, options);
363340

364-
// Ensure the query is an object
365-
if (selector != null && typeof selector !== 'object') {
366-
throw MongoError.create({ message: 'query selector must be an object', driver: true });
367-
}
341+
// Make a shallow copy of the collection options
342+
for (let key in this.s.options) {
343+
if (mergeKeys.indexOf(key) !== -1) {
344+
newOptions[key] = this.s.options[key];
345+
}
346+
}
368347

369-
// Build the find command
370-
const findCommand = {
371-
find: this.s.namespace,
372-
limit: newOptions.limit,
373-
skip: newOptions.skip,
374-
query: selector
375-
};
348+
// Unpack options
349+
newOptions.skip = options.skip ? options.skip : 0;
350+
newOptions.limit = options.limit ? options.limit : 0;
351+
newOptions.raw = typeof options.raw === 'boolean' ? options.raw : this.s.raw;
352+
newOptions.hint =
353+
options.hint != null ? normalizeHintField(options.hint) : this.s.collectionHint;
354+
newOptions.timeout = typeof options.timeout === 'undefined' ? undefined : options.timeout;
355+
// // If we have overridden slaveOk otherwise use the default db setting
356+
newOptions.slaveOk = options.slaveOk != null ? options.slaveOk : this.s.db.slaveOk;
357+
358+
// Add read preference if needed
359+
newOptions.readPreference = resolveReadPreference(newOptions, {
360+
db: this.s.db,
361+
collection: this
362+
});
376363

377-
// Ensure we use the right await data option
378-
if (typeof newOptions.awaitdata === 'boolean') {
379-
newOptions.awaitData = newOptions.awaitdata;
380-
}
364+
// Set slave ok to true if read preference different from primary
365+
if (
366+
newOptions.readPreference != null &&
367+
(newOptions.readPreference !== 'primary' || newOptions.readPreference.mode !== 'primary')
368+
) {
369+
newOptions.slaveOk = true;
370+
}
381371

382-
// Translate to new command option noCursorTimeout
383-
if (typeof newOptions.timeout === 'boolean') newOptions.noCursorTimeout = newOptions.timeout;
372+
// Ensure the query is an object
373+
if (selector != null && typeof selector !== 'object') {
374+
throw MongoError.create({ message: 'query selector must be an object', driver: true });
375+
}
384376

385-
// Merge in options to command
386-
for (let name in newOptions) {
387-
if (newOptions[name] != null && name !== 'session') {
388-
findCommand[name] = newOptions[name];
377+
// Build the find command
378+
const findCommand = {
379+
find: this.s.namespace,
380+
limit: newOptions.limit,
381+
skip: newOptions.skip,
382+
query: selector
383+
};
384+
385+
// Ensure we use the right await data option
386+
if (typeof newOptions.awaitdata === 'boolean') {
387+
newOptions.awaitData = newOptions.awaitdata;
389388
}
390-
}
391389

392-
DEPRECATED_FIND_OPTIONS.forEach(deprecatedOption => {
393-
if (findCommand[deprecatedOption]) {
394-
console.warn(
395-
`Find option ${deprecatedOption} is deprecated, and will be removed in a later version`
396-
);
390+
// Translate to new command option noCursorTimeout
391+
if (typeof newOptions.timeout === 'boolean') newOptions.noCursorTimeout = newOptions.timeout;
392+
393+
// Merge in options to command
394+
for (let name in newOptions) {
395+
if (newOptions[name] != null && name !== 'session') {
396+
findCommand[name] = newOptions[name];
397+
}
397398
}
398-
});
399399

400-
if (projection) findCommand.fields = projection;
400+
if (projection) findCommand.fields = projection;
401401

402-
// Add db object to the new options
403-
newOptions.db = this.s.db;
402+
// Add db object to the new options
403+
newOptions.db = this.s.db;
404404

405-
// Add the promise library
406-
newOptions.promiseLibrary = this.s.promiseLibrary;
405+
// Add the promise library
406+
newOptions.promiseLibrary = this.s.promiseLibrary;
407407

408-
// Set raw if available at collection level
409-
if (newOptions.raw == null && typeof this.s.raw === 'boolean') newOptions.raw = this.s.raw;
410-
// Set promoteLongs if available at collection level
411-
if (newOptions.promoteLongs == null && typeof this.s.promoteLongs === 'boolean')
412-
newOptions.promoteLongs = this.s.promoteLongs;
413-
if (newOptions.promoteValues == null && typeof this.s.promoteValues === 'boolean')
414-
newOptions.promoteValues = this.s.promoteValues;
415-
if (newOptions.promoteBuffers == null && typeof this.s.promoteBuffers === 'boolean')
416-
newOptions.promoteBuffers = this.s.promoteBuffers;
408+
// Set raw if available at collection level
409+
if (newOptions.raw == null && typeof this.s.raw === 'boolean') newOptions.raw = this.s.raw;
410+
// Set promoteLongs if available at collection level
411+
if (newOptions.promoteLongs == null && typeof this.s.promoteLongs === 'boolean')
412+
newOptions.promoteLongs = this.s.promoteLongs;
413+
if (newOptions.promoteValues == null && typeof this.s.promoteValues === 'boolean')
414+
newOptions.promoteValues = this.s.promoteValues;
415+
if (newOptions.promoteBuffers == null && typeof this.s.promoteBuffers === 'boolean')
416+
newOptions.promoteBuffers = this.s.promoteBuffers;
417417

418-
// Sort options
419-
if (findCommand.sort) {
420-
findCommand.sort = formattedOrderClause(findCommand.sort);
421-
}
418+
// Sort options
419+
if (findCommand.sort) {
420+
findCommand.sort = formattedOrderClause(findCommand.sort);
421+
}
422422

423-
// Set the readConcern
424-
decorateWithReadConcern(findCommand, this, options);
423+
// Set the readConcern
424+
decorateWithReadConcern(findCommand, this, options);
425425

426-
// Decorate find command with collation options
427-
decorateWithCollation(findCommand, this, options);
426+
// Decorate find command with collation options
427+
decorateWithCollation(findCommand, this, options);
428428

429-
const cursor = this.s.topology.cursor(this.s.namespace, findCommand, newOptions);
429+
const cursor = this.s.topology.cursor(this.s.namespace, findCommand, newOptions);
430430

431-
return typeof callback === 'function' ? handleCallback(callback, null, cursor) : cursor;
432-
};
431+
return typeof callback === 'function' ? handleCallback(callback, null, cursor) : cursor;
432+
}
433+
);
433434

434435
/**
435436
* Inserts a single document into MongoDB. If documents passed in do not contain the **_id** field,
@@ -662,7 +663,7 @@ Collection.prototype.bulkWrite = function(operations, options, callback) {
662663
* @return {Promise} returns Promise if no callback passed
663664
* @deprecated Use insertOne, insertMany or bulkWrite
664665
*/
665-
Collection.prototype.insert = function(docs, options, callback) {
666+
Collection.prototype.insert = deprecate(function(docs, options, callback) {
666667
if (typeof options === 'function') (callback = options), (options = {});
667668
options = options || { ordered: false };
668669
docs = !Array.isArray(docs) ? [docs] : docs;
@@ -672,7 +673,7 @@ Collection.prototype.insert = function(docs, options, callback) {
672673
}
673674

674675
return this.insertMany(docs, options, callback);
675-
};
676+
}, 'collection.insert is deprecated. Use insertOne, insertMany or bulkWrite instead.');
676677

677678
/**
678679
* @typedef {Object} Collection~updateWriteOpResult
@@ -816,7 +817,7 @@ Collection.prototype.updateMany = function(filter, update, options, callback) {
816817
* @return {Promise} returns Promise if no callback passed
817818
* @deprecated use updateOne, updateMany or bulkWrite
818819
*/
819-
Collection.prototype.update = function(selector, document, options, callback) {
820+
Collection.prototype.update = deprecate(function(selector, document, options, callback) {
820821
if (typeof options === 'function') (callback = options), (options = {});
821822
options = options || {};
822823

@@ -833,7 +834,7 @@ Collection.prototype.update = function(selector, document, options, callback) {
833834
options,
834835
callback
835836
]);
836-
};
837+
}, 'collection.update is deprecated. Use updateOne, updateMany, or bulkWrite instead.');
837838

838839
/**
839840
* @typedef {Object} Collection~deleteWriteOpResult
@@ -919,7 +920,7 @@ Collection.prototype.removeMany = Collection.prototype.deleteMany;
919920
* @return {Promise} returns Promise if no callback passed
920921
* @deprecated use deleteOne, deleteMany or bulkWrite
921922
*/
922-
Collection.prototype.remove = function(selector, options, callback) {
923+
Collection.prototype.remove = deprecate(function(selector, options, callback) {
923924
if (typeof options === 'function') (callback = options), (options = {});
924925
options = options || {};
925926

@@ -930,7 +931,7 @@ Collection.prototype.remove = function(selector, options, callback) {
930931
}
931932

932933
return executeOperation(this.s.topology, removeDocuments, [this, selector, options, callback]);
933-
};
934+
}, 'collection.remove is deprecated. Use deleteOne, deleteMany, or bulkWrite instead.');
934935

935936
/**
936937
* Save a document. Simple full document replacement function. Not recommended for efficiency, use atomic
@@ -946,7 +947,7 @@ Collection.prototype.remove = function(selector, options, callback) {
946947
* @return {Promise} returns Promise if no callback passed
947948
* @deprecated use insertOne, insertMany, updateOne or updateMany
948949
*/
949-
Collection.prototype.save = function(doc, options, callback) {
950+
Collection.prototype.save = deprecate(function(doc, options, callback) {
950951
if (typeof options === 'function') (callback = options), (options = {});
951952
options = options || {};
952953

@@ -957,7 +958,7 @@ Collection.prototype.save = function(doc, options, callback) {
957958
}
958959

959960
return executeOperation(this.s.topology, save, [this, doc, options, callback]);
960-
};
961+
}, 'collection.save is deprecated. Use insertOne, insertMany, updateOne, or updateMany instead.');
961962

962963
/**
963964
* The callback format for results
@@ -1007,19 +1008,26 @@ Collection.prototype.save = function(doc, options, callback) {
10071008
* @param {Collection~resultCallback} [callback] The command result callback
10081009
* @return {Promise} returns Promise if no callback passed
10091010
*/
1010-
Collection.prototype.findOne = function(query, options, callback) {
1011-
if (typeof callback === 'object') {
1012-
// TODO(MAJOR): throw in the future
1013-
console.warn('Third parameter to `findOne()` must be a callback or undefined');
1014-
}
1011+
Collection.prototype.findOne = deprecateOptions(
1012+
{
1013+
name: 'collection.find',
1014+
deprecatedOptions: DEPRECATED_FIND_OPTIONS,
1015+
optionsIndex: 1
1016+
},
1017+
function(query, options, callback) {
1018+
if (typeof callback === 'object') {
1019+
// TODO(MAJOR): throw in the future
1020+
console.warn('Third parameter to `findOne()` must be a callback or undefined');
1021+
}
10151022

1016-
if (typeof query === 'function') (callback = query), (query = {}), (options = {});
1017-
if (typeof options === 'function') (callback = options), (options = {});
1018-
query = query || {};
1019-
options = options || {};
1023+
if (typeof query === 'function') (callback = query), (query = {}), (options = {});
1024+
if (typeof options === 'function') (callback = options), (options = {});
1025+
query = query || {};
1026+
options = options || {};
10201027

1021-
return executeOperation(this.s.topology, findOne, [this, query, options, callback]);
1022-
};
1028+
return executeOperation(this.s.topology, findOne, [this, query, options, callback]);
1029+
}
1030+
);
10231031

10241032
/**
10251033
* The callback format for the collection method, must be used if strict is specified
@@ -1197,7 +1205,10 @@ Collection.prototype.dropIndexes = function(options, callback) {
11971205
* @param {Collection~resultCallback} callback The command result callback
11981206
* @return {Promise} returns Promise if no [callback] passed
11991207
*/
1200-
Collection.prototype.dropAllIndexes = Collection.prototype.dropIndexes;
1208+
Collection.prototype.dropAllIndexes = deprecate(
1209+
Collection.prototype.dropIndexes,
1210+
'collection.dropAllIndexes is deprecated. Use dropIndexes instead.'
1211+
);
12011212

12021213
/**
12031214
* Reindex all indexes on the collection
@@ -1290,12 +1301,12 @@ Collection.prototype.listIndexes = function(options) {
12901301
* @param {Collection~resultCallback} [callback] The command result callback
12911302
* @return {Promise} returns Promise if no callback passed
12921303
*/
1293-
Collection.prototype.ensureIndex = function(fieldOrSpec, options, callback) {
1304+
Collection.prototype.ensureIndex = deprecate(function(fieldOrSpec, options, callback) {
12941305
if (typeof options === 'function') (callback = options), (options = {});
12951306
options = options || {};
12961307

12971308
return executeOperation(this.s.topology, ensureIndex, [this, fieldOrSpec, options, callback]);
1298-
};
1309+
}, 'collection.ensureIndex is deprecated. Use createIndexes instead.');
12991310

13001311
/**
13011312
* Checks if one or more indexes exist on the collection, fails on first non-existing index
@@ -1634,7 +1645,7 @@ Collection.prototype.findOneAndUpdate = function(filter, update, options, callba
16341645
* @return {Promise} returns Promise if no callback passed
16351646
* @deprecated use findOneAndUpdate, findOneAndReplace or findOneAndDelete instead
16361647
*/
1637-
Collection.prototype.findAndModify = function(query, sort, doc, options, callback) {
1648+
Collection.prototype.findAndModify = deprecate(function(query, sort, doc, options, callback) {
16381649
const args = Array.prototype.slice.call(arguments, 1);
16391650
callback = typeof args[args.length - 1] === 'function' ? args.pop() : undefined;
16401651
sort = args.length ? args.shift() || [] : [];
@@ -1654,7 +1665,7 @@ Collection.prototype.findAndModify = function(query, sort, doc, options, callbac
16541665
options,
16551666
callback
16561667
]);
1657-
};
1668+
}, 'collection.findAndModify is deprecated. Use findOneAndUpdate, findOneAndReplace or findOneAndDelete instead.');
16581669

16591670
/**
16601671
* Find and remove a document.
@@ -1670,14 +1681,14 @@ Collection.prototype.findAndModify = function(query, sort, doc, options, callbac
16701681
* @return {Promise} returns Promise if no callback passed
16711682
* @deprecated use findOneAndDelete instead
16721683
*/
1673-
Collection.prototype.findAndRemove = function(query, sort, options, callback) {
1684+
Collection.prototype.findAndRemove = deprecate(function(query, sort, options, callback) {
16741685
const args = Array.prototype.slice.call(arguments, 1);
16751686
callback = typeof args[args.length - 1] === 'function' ? args.pop() : undefined;
16761687
sort = args.length ? args.shift() || [] : [];
16771688
options = args.length ? args.shift() || {} : {};
16781689

16791690
return executeOperation(this.s.topology, findAndRemove, [this, query, sort, options, callback]);
1680-
};
1691+
}, 'collection.findAndRemove is deprecated. Use findOneAndDelete instead.');
16811692

16821693
/**
16831694
* Execute an aggregation framework pipeline against the collection, needs MongoDB >= 2.2
@@ -1933,9 +1944,9 @@ Collection.prototype.geoHaystackSearch = function(x, y, options, callback) {
19331944
* @param {ClientSession} [options.session] optional session to use for this operation
19341945
* @param {Collection~resultCallback} [callback] The command result callback
19351946
* @return {Promise} returns Promise if no callback passed
1936-
* @deprecated MongoDB 3.6 or higher will no longer support the group command. We recommend rewriting using the aggregation framework.
1947+
* @deprecated MongoDB 3.6 or higher no longer supports the group command. We recommend rewriting using the aggregation framework.
19371948
*/
1938-
Collection.prototype.group = function(
1949+
Collection.prototype.group = deprecate(function(
19391950
keys,
19401951
condition,
19411952
initial,
@@ -1989,7 +2000,8 @@ Collection.prototype.group = function(
19892000
options,
19902001
callback
19912002
]);
1992-
};
2003+
},
2004+
'MongoDB 3.6 or higher no longer supports the group command. We recommend rewriting using the aggregation framework.');
19932005

19942006
/**
19952007
* Run Map Reduce across a collection. Be aware that the inline option for out will return an array of results not a collection.

‎lib/cursor.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -699,14 +699,14 @@ Cursor.prototype.skip = function(value) {
699699
* @throws {MongoError}
700700
* @return {null}
701701
*/
702-
Cursor.prototype.each = function(callback) {
702+
Cursor.prototype.each = deprecate(function(callback) {
703703
// Rewind cursor state
704704
this.rewind();
705705
// Set current cursor to INIT
706706
this.s.state = Cursor.INIT;
707707
// Run the query
708708
each(this, callback);
709-
};
709+
}, 'Cursor.each is deprecated. Use Cursor.forEach instead.');
710710

711711
/**
712712
* The callback format for the forEach iterator method

‎lib/db.js

+21-16
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ const executeOperation = require('./utils').executeOperation;
1717
const applyWriteConcern = require('./utils').applyWriteConcern;
1818
const resolveReadPreference = require('./utils').resolveReadPreference;
1919
const ChangeStream = require('./change_stream');
20+
const deprecate = require('util').deprecate;
21+
const deprecateOptions = require('./utils').deprecateOptions;
2022

2123
// Operations
2224
const addUser = require('./operations/db_ops').addUser;
@@ -414,17 +416,20 @@ Db.prototype.collection = function(name, options, callback) {
414416
* @param {Db~collectionResultCallback} [callback] The results callback
415417
* @return {Promise} returns Promise if no callback passed
416418
*/
417-
Db.prototype.createCollection = function(name, options, callback) {
418-
if (typeof options === 'function') (callback = options), (options = {});
419-
options = options || {};
420-
options.promiseLibrary = options.promiseLibrary || this.s.promiseLibrary;
421-
422-
if (options.autoIndexId !== undefined) {
423-
console.warn('the autoIndexId option is deprecated and will be removed in a future release');
419+
Db.prototype.createCollection = deprecateOptions(
420+
{
421+
name: 'Db.createCollection',
422+
deprecatedOptions: ['autoIndexId'],
423+
optionsIndex: 1
424+
},
425+
function(name, options, callback) {
426+
if (typeof options === 'function') (callback = options), (options = {});
427+
options = options || {};
428+
options.promiseLibrary = options.promiseLibrary || this.s.promiseLibrary;
429+
430+
return executeOperation(this.s.topology, createCollection, [this, name, options, callback]);
424431
}
425-
426-
return executeOperation(this.s.topology, createCollection, [this, name, options, callback]);
427-
};
432+
);
428433

429434
/**
430435
* Get all the db statistics.
@@ -549,14 +554,14 @@ Db.prototype.listCollections = function(filter, options) {
549554
* @deprecated Eval is deprecated on MongoDB 3.2 and forward
550555
* @return {Promise} returns Promise if no callback passed
551556
*/
552-
Db.prototype.eval = function(code, parameters, options, callback) {
557+
Db.prototype.eval = deprecate(function(code, parameters, options, callback) {
553558
const args = Array.prototype.slice.call(arguments, 1);
554559
callback = typeof args[args.length - 1] === 'function' ? args.pop() : undefined;
555560
parameters = args.length ? args.shift() : parameters;
556561
options = args.length ? args.shift() || {} : {};
557562

558563
return executeOperation(this.s.topology, evaluate, [this, code, parameters, options, callback]);
559-
};
564+
}, 'Db.eval is deprecated as of MongoDB version 3.2');
560565

561566
/**
562567
* Rename a collection.
@@ -739,7 +744,7 @@ Db.prototype.createIndex = function(name, fieldOrSpec, options, callback) {
739744
* @param {Db~resultCallback} [callback] The command result callback
740745
* @return {Promise} returns Promise if no callback passed
741746
*/
742-
Db.prototype.ensureIndex = function(name, fieldOrSpec, options, callback) {
747+
Db.prototype.ensureIndex = deprecate(function(name, fieldOrSpec, options, callback) {
743748
if (typeof options === 'function') (callback = options), (options = {});
744749
options = options || {};
745750

@@ -750,7 +755,7 @@ Db.prototype.ensureIndex = function(name, fieldOrSpec, options, callback) {
750755
options,
751756
callback
752757
]);
753-
};
758+
}, 'Db.ensureIndex is deprecated as of MongoDB version 3.0 / driver version 2.0');
754759

755760
Db.prototype.addChild = function(db) {
756761
if (this.s.parentDb) return this.s.parentDb.addChild(db);
@@ -823,12 +828,12 @@ Db.prototype.setProfilingLevel = function(level, options, callback) {
823828
* @return {Promise} returns Promise if no callback passed
824829
* @deprecated Query the system.profile collection directly.
825830
*/
826-
Db.prototype.profilingInfo = function(options, callback) {
831+
Db.prototype.profilingInfo = deprecate(function(options, callback) {
827832
if (typeof options === 'function') (callback = options), (options = {});
828833
options = options || {};
829834

830835
return executeOperation(this.s.topology, profilingInfo, [this, options, callback]);
831-
};
836+
}, 'Db.profilingInfo is deprecated. Query the system.profile collection directly.');
832837

833838
/**
834839
* Retrieve the current profiling Level for MongoDB

0 commit comments

Comments
 (0)
Please sign in to comment.