Cleanup
This commit is contained in:
368
node_modules/mongodb/lib/collection.js
generated
vendored
368
node_modules/mongodb/lib/collection.js
generated
vendored
@@ -2,10 +2,10 @@
|
||||
|
||||
const deprecate = require('util').deprecate;
|
||||
const deprecateOptions = require('./utils').deprecateOptions;
|
||||
const emitWarningOnce = require('./utils').emitWarningOnce;
|
||||
const checkCollectionName = require('./utils').checkCollectionName;
|
||||
const ObjectID = require('./core').BSON.ObjectID;
|
||||
const MongoError = require('./core').MongoError;
|
||||
const toError = require('./utils').toError;
|
||||
const normalizeHintField = require('./utils').normalizeHintField;
|
||||
const decorateCommand = require('./utils').decorateCommand;
|
||||
const decorateWithCollation = require('./utils').decorateWithCollation;
|
||||
@@ -16,7 +16,6 @@ const unordered = require('./bulk/unordered');
|
||||
const ordered = require('./bulk/ordered');
|
||||
const ChangeStream = require('./change_stream');
|
||||
const executeLegacyOperation = require('./utils').executeLegacyOperation;
|
||||
const resolveReadPreference = require('./utils').resolveReadPreference;
|
||||
const WriteConcern = require('./write_concern');
|
||||
const ReadConcern = require('./read_concern');
|
||||
const MongoDBNamespace = require('./utils').MongoDBNamespace;
|
||||
@@ -24,7 +23,6 @@ const AggregationCursor = require('./aggregation_cursor');
|
||||
const CommandCursor = require('./command_cursor');
|
||||
|
||||
// Operations
|
||||
const checkForAtomicOperators = require('./operations/collection_ops').checkForAtomicOperators;
|
||||
const ensureIndex = require('./operations/collection_ops').ensureIndex;
|
||||
const group = require('./operations/collection_ops').group;
|
||||
const parallelCollectionScan = require('./operations/collection_ops').parallelCollectionScan;
|
||||
@@ -35,7 +33,6 @@ const updateDocuments = require('./operations/common_functions').updateDocuments
|
||||
const AggregateOperation = require('./operations/aggregate');
|
||||
const BulkWriteOperation = require('./operations/bulk_write');
|
||||
const CountDocumentsOperation = require('./operations/count_documents');
|
||||
const CreateIndexOperation = require('./operations/create_index');
|
||||
const CreateIndexesOperation = require('./operations/create_indexes');
|
||||
const DeleteManyOperation = require('./operations/delete_many');
|
||||
const DeleteOneOperation = require('./operations/delete_one');
|
||||
@@ -123,6 +120,8 @@ function Collection(db, topology, dbName, name, pkFactory, options) {
|
||||
options == null || options.promoteBuffers == null
|
||||
? db.s.options.promoteBuffers
|
||||
: options.promoteBuffers;
|
||||
const bsonRegExp =
|
||||
options == null || options.bsonRegExp == null ? db.s.options.bsonRegExp : options.bsonRegExp;
|
||||
const collectionHint = null;
|
||||
|
||||
const namespace = new MongoDBNamespace(dbName, name);
|
||||
@@ -159,6 +158,8 @@ function Collection(db, topology, dbName, name, pkFactory, options) {
|
||||
promoteValues: promoteValues,
|
||||
// promoteBuffers
|
||||
promoteBuffers: promoteBuffers,
|
||||
// bsonRegExp
|
||||
bsonRegExp: bsonRegExp,
|
||||
// internalHint
|
||||
internalHint: internalHint,
|
||||
// collectionHint
|
||||
@@ -278,7 +279,7 @@ Object.defineProperty(Collection.prototype, 'hint', {
|
||||
}
|
||||
});
|
||||
|
||||
const DEPRECATED_FIND_OPTIONS = ['maxScan', 'fields', 'snapshot'];
|
||||
const DEPRECATED_FIND_OPTIONS = ['maxScan', 'fields', 'snapshot', 'oplogReplay'];
|
||||
|
||||
/**
|
||||
* Creates a cursor for a query that can be used to iterate over results from MongoDB
|
||||
@@ -291,7 +292,6 @@ const DEPRECATED_FIND_OPTIONS = ['maxScan', 'fields', 'snapshot'];
|
||||
* @param {object} [options.fields] **Deprecated** Use `options.projection` instead
|
||||
* @param {number} [options.skip=0] Set to skip N documents ahead in your query (useful for pagination).
|
||||
* @param {Object} [options.hint] Tell the query to use specific indexes in the query. Object of indexes to use, {'_id':1}
|
||||
* @param {boolean} [options.explain=false] Explain the query instead of returning the data.
|
||||
* @param {boolean} [options.snapshot=false] DEPRECATED: Snapshot query.
|
||||
* @param {boolean} [options.timeout=false] Specify if the cursor can timeout.
|
||||
* @param {boolean} [options.tailable=false] Specify if the cursor is tailable.
|
||||
@@ -307,12 +307,15 @@ const DEPRECATED_FIND_OPTIONS = ['maxScan', 'fields', 'snapshot'];
|
||||
* @param {boolean} [options.promoteLongs=true] Promotes Long values to number if they fit inside the 53 bits resolution.
|
||||
* @param {boolean} [options.promoteValues=true] Promotes BSON values to native types where possible, set to false to only receive wrapper types.
|
||||
* @param {boolean} [options.promoteBuffers=false] Promotes Binary BSON values to native Node Buffers.
|
||||
* @param {boolean} [options.bsonRegExp=false] By default, regex returned from MDB will be native to the language. Setting to true will ensure that a BSON.BSONRegExp object is returned.
|
||||
* @param {(ReadPreference|string)} [options.readPreference] The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
|
||||
* @param {boolean} [options.partial=false] Specify if the cursor should return partial results when querying against a sharded system
|
||||
* @param {number} [options.maxTimeMS] Number of milliseconds to wait before aborting the query.
|
||||
* @param {number} [options.maxAwaitTimeMS] The maximum amount of time for the server to wait on new documents to satisfy a tailable cursor query. Requires `tailable` and `awaitData` to be true
|
||||
* @param {boolean} [options.noCursorTimeout] The server normally times out idle cursors after an inactivity period (10 minutes) to prevent excess memory use. Set this option to prevent that.
|
||||
* @param {object} [options.collation] Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).
|
||||
* @param {boolean} [options.allowDiskUse] Enables writing to temporary files on the server.
|
||||
* @param {'queryPlanner'|'queryPlannerExtended'|'executionStats'|'allPlansExecution'|boolean} [options.explain] The verbosity mode for the explain output.
|
||||
* @param {ClientSession} [options.session] optional session to use for this operation
|
||||
* @throws {MongoError}
|
||||
* @return {Cursor}
|
||||
@@ -326,7 +329,7 @@ Collection.prototype.find = deprecateOptions(
|
||||
function(query, options, callback) {
|
||||
if (typeof callback === 'object') {
|
||||
// TODO(MAJOR): throw in the future
|
||||
console.warn('Third parameter to `find()` must be a callback or undefined');
|
||||
emitWarningOnce('Third parameter to `find()` must be a callback or undefined');
|
||||
}
|
||||
|
||||
let selector = query;
|
||||
@@ -399,7 +402,7 @@ Collection.prototype.find = deprecateOptions(
|
||||
newOptions.slaveOk = options.slaveOk != null ? options.slaveOk : this.s.db.slaveOk;
|
||||
|
||||
// Add read preference if needed
|
||||
newOptions.readPreference = resolveReadPreference(this, newOptions);
|
||||
newOptions.readPreference = ReadPreference.resolve(this, newOptions);
|
||||
|
||||
// Set slave ok to true if read preference different from primary
|
||||
if (
|
||||
@@ -422,13 +425,17 @@ Collection.prototype.find = deprecateOptions(
|
||||
query: selector
|
||||
};
|
||||
|
||||
if (typeof options.allowDiskUse === 'boolean') {
|
||||
findCommand.allowDiskUse = options.allowDiskUse;
|
||||
}
|
||||
|
||||
// Ensure we use the right await data option
|
||||
if (typeof newOptions.awaitdata === 'boolean') {
|
||||
newOptions.awaitData = newOptions.awaitdata;
|
||||
}
|
||||
|
||||
// Translate to new command option noCursorTimeout
|
||||
if (typeof newOptions.timeout === 'boolean') newOptions.noCursorTimeout = newOptions.timeout;
|
||||
if (typeof newOptions.timeout === 'boolean') newOptions.noCursorTimeout = !newOptions.timeout;
|
||||
|
||||
decorateCommand(findCommand, newOptions, ['session', 'collation']);
|
||||
|
||||
@@ -449,6 +456,8 @@ Collection.prototype.find = deprecateOptions(
|
||||
newOptions.promoteValues = this.s.promoteValues;
|
||||
if (newOptions.promoteBuffers == null && typeof this.s.promoteBuffers === 'boolean')
|
||||
newOptions.promoteBuffers = this.s.promoteBuffers;
|
||||
if (newOptions.bsonRegExp == null && typeof this.s.bsonRegExp === 'boolean')
|
||||
newOptions.bsonRegExp = this.s.bsonRegExp;
|
||||
|
||||
// Sort options
|
||||
if (findCommand.sort) {
|
||||
@@ -491,9 +500,10 @@ Collection.prototype.find = deprecateOptions(
|
||||
* @param {object} [options] Optional settings.
|
||||
* @param {boolean} [options.bypassDocumentValidation=false] Allow driver to bypass schema validation in MongoDB 3.2 or higher.
|
||||
* @param {boolean} [options.forceServerObjectId=false] Force server to assign _id values instead of driver.
|
||||
* @param {(number|string)} [options.w] The write concern.
|
||||
* @param {number} [options.wtimeout] The write concern timeout.
|
||||
* @param {boolean} [options.j=false] Specify a journal write concern.
|
||||
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
|
||||
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
|
||||
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
|
||||
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
|
||||
* @param {boolean} [options.checkKeys=true] If true, will throw if bson documents start with `$` or include a `.` in any key value
|
||||
* @param {boolean} [options.serializeFunctions=false] Serialize functions on any object.
|
||||
* @param {boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields.
|
||||
@@ -527,9 +537,10 @@ Collection.prototype.insertOne = function(doc, options, callback) {
|
||||
* @param {boolean} [options.bypassDocumentValidation=false] Allow driver to bypass schema validation in MongoDB 3.2 or higher.
|
||||
* @param {boolean} [options.ordered=true] If true, when an insert fails, don't execute the remaining writes. If false, continue with remaining inserts when one fails.
|
||||
* @param {boolean} [options.forceServerObjectId=false] Force server to assign _id values instead of driver.
|
||||
* @param {(number|string)} [options.w] The write concern.
|
||||
* @param {number} [options.wtimeout] The write concern timeout.
|
||||
* @param {boolean} [options.j=false] Specify a journal write concern.
|
||||
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
|
||||
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
|
||||
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
|
||||
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
|
||||
* @param {boolean} [options.checkKeys=true] If true, will throw if bson documents start with `$` or include a `.` in any key value
|
||||
* @param {boolean} [options.serializeFunctions=false] Serialize functions on any object.
|
||||
* @param {boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields.
|
||||
@@ -594,9 +605,10 @@ Collection.prototype.insertMany = function(docs, options, callback) {
|
||||
* @param {boolean} [options.ordered=true] Execute write operation in ordered or unordered fashion.
|
||||
* @param {boolean} [options.bypassDocumentValidation=false] Allow driver to bypass schema validation in MongoDB 3.2 or higher.
|
||||
* @param {object[]} [options.arrayFilters] Determines which array elements to modify for update operation in MongoDB 3.6 or higher.
|
||||
* @param {(number|string)} [options.w] The write concern.
|
||||
* @param {number} [options.wtimeout] The write concern timeout.
|
||||
* @param {boolean} [options.j=false] Specify a journal write concern.
|
||||
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
|
||||
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
|
||||
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
|
||||
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
|
||||
* @param {boolean} [options.checkKeys=false] If true, will throw if bson documents start with `$` or include a `.` in any key value
|
||||
* @param {boolean} [options.serializeFunctions=false] Serialize functions on any object.
|
||||
* @param {boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields.
|
||||
@@ -675,9 +687,10 @@ Collection.prototype.bulkWrite = function(operations, options, callback) {
|
||||
* @method
|
||||
* @param {(object|object[])} docs Documents to insert.
|
||||
* @param {object} [options] Optional settings.
|
||||
* @param {(number|string)} [options.w] The write concern.
|
||||
* @param {number} [options.wtimeout] The write concern timeout.
|
||||
* @param {boolean} [options.j=false] Specify a journal write concern.
|
||||
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
|
||||
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
|
||||
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
|
||||
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
|
||||
* @param {boolean} [options.serializeFunctions=false] Serialize functions on any object.
|
||||
* @param {boolean} [options.forceServerObjectId=false] Force server to assign _id values instead of driver.
|
||||
* @param {boolean} [options.bypassDocumentValidation=false] Allow driver to bypass schema validation in MongoDB 3.2 or higher.
|
||||
@@ -732,26 +745,20 @@ Collection.prototype.insert = deprecate(function(docs, options, callback) {
|
||||
* @param {object} [options.collation] Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).
|
||||
* @param {object} [options.hint] An optional hint for query optimization. See the {@link https://docs.mongodb.com/manual/reference/command/update/#update-command-hint|update command} reference for more information.
|
||||
* @param {boolean} [options.upsert=false] When true, creates a new document if no document matches the query..
|
||||
* @param {(number|string)} [options.w] The write concern.
|
||||
* @param {number} [options.wtimeout] The write concern timeout.
|
||||
* @param {boolean} [options.j=false] Specify a journal write concern.
|
||||
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
|
||||
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
|
||||
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
|
||||
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
|
||||
* @param {boolean} [options.checkKeys=false] If true, will throw if bson documents start with `$` or include a `.` in any key value
|
||||
* @param {boolean} [options.serializeFunctions=false] Serialize functions on any object.
|
||||
* @param {boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields.
|
||||
* @param {'queryPlanner'|'queryPlannerExtended'|'executionStats'|'allPlansExecution'|boolean} [options.explain] The verbosity mode for the explain output.
|
||||
* @param {ClientSession} [options.session] optional session to use for this operation
|
||||
* @param {Collection~updateWriteOpCallback} [callback] The command result callback
|
||||
* @return {Promise} returns Promise if no callback passed
|
||||
*/
|
||||
Collection.prototype.updateOne = function(filter, update, options, callback) {
|
||||
if (typeof options === 'function') (callback = options), (options = {});
|
||||
options = options || {};
|
||||
|
||||
const err = checkForAtomicOperators(update);
|
||||
if (err) {
|
||||
if (typeof callback === 'function') return callback(err);
|
||||
return this.s.promiseLibrary.reject(err);
|
||||
}
|
||||
|
||||
options = Object.assign({}, options);
|
||||
|
||||
// Add ignoreUndefined
|
||||
@@ -760,9 +767,11 @@ Collection.prototype.updateOne = function(filter, update, options, callback) {
|
||||
options.ignoreUndefined = this.s.options.ignoreUndefined;
|
||||
}
|
||||
|
||||
const updateOneOperation = new UpdateOneOperation(this, filter, update, options);
|
||||
|
||||
return executeOperation(this.s.topology, updateOneOperation, callback);
|
||||
return executeOperation(
|
||||
this.s.topology,
|
||||
new UpdateOneOperation(this, filter, update, options),
|
||||
callback
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -775,9 +784,10 @@ Collection.prototype.updateOne = function(filter, update, options, callback) {
|
||||
* @param {object} [options.collation] Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).
|
||||
* @param {object} [options.hint] An optional hint for query optimization. See the {@link https://docs.mongodb.com/manual/reference/command/update/#update-command-hint|update command} reference for more information.
|
||||
* @param {boolean} [options.upsert=false] When true, creates a new document if no document matches the query.
|
||||
* @param {(number|string)} [options.w] The write concern.
|
||||
* @param {number} [options.wtimeout] The write concern timeout.
|
||||
* @param {boolean} [options.j=false] Specify a journal write concern.
|
||||
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
|
||||
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
|
||||
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
|
||||
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
|
||||
* @param {boolean} [options.checkKeys=false] If true, will throw if bson documents start with `$` or include a `.` in any key value
|
||||
* @param {boolean} [options.serializeFunctions=false] Serialize functions on any object.
|
||||
* @param {boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields.
|
||||
@@ -795,9 +805,11 @@ Collection.prototype.replaceOne = function(filter, doc, options, callback) {
|
||||
options.ignoreUndefined = this.s.options.ignoreUndefined;
|
||||
}
|
||||
|
||||
const replaceOneOperation = new ReplaceOneOperation(this, filter, doc, options);
|
||||
|
||||
return executeOperation(this.s.topology, replaceOneOperation, callback);
|
||||
return executeOperation(
|
||||
this.s.topology,
|
||||
new ReplaceOneOperation(this, filter, doc, options),
|
||||
callback
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -811,26 +823,20 @@ Collection.prototype.replaceOne = function(filter, doc, options, callback) {
|
||||
* @param {object} [options.collation] Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).
|
||||
* @param {object} [options.hint] An optional hint for query optimization. See the {@link https://docs.mongodb.com/manual/reference/command/update/#update-command-hint|update command} reference for more information.
|
||||
* @param {boolean} [options.upsert=false] When true, creates a new document if no document matches the query..
|
||||
* @param {(number|string)} [options.w] The write concern.
|
||||
* @param {number} [options.wtimeout] The write concern timeout.
|
||||
* @param {boolean} [options.j=false] Specify a journal write concern.
|
||||
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
|
||||
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
|
||||
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
|
||||
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
|
||||
* @param {boolean} [options.checkKeys=false] If true, will throw if bson documents start with `$` or include a `.` in any key value
|
||||
* @param {boolean} [options.serializeFunctions=false] Serialize functions on any object.
|
||||
* @param {boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields.
|
||||
* @param {'queryPlanner'|'queryPlannerExtended'|'executionStats'|'allPlansExecution'|boolean} [options.explain] The verbosity mode for the explain output.
|
||||
* @param {ClientSession} [options.session] optional session to use for this operation
|
||||
* @param {Collection~updateWriteOpCallback} [callback] The command result callback
|
||||
* @return {Promise<Collection~updateWriteOpResult>} returns Promise if no callback passed
|
||||
*/
|
||||
Collection.prototype.updateMany = function(filter, update, options, callback) {
|
||||
if (typeof options === 'function') (callback = options), (options = {});
|
||||
options = options || {};
|
||||
|
||||
const err = checkForAtomicOperators(update);
|
||||
if (err) {
|
||||
if (typeof callback === 'function') return callback(err);
|
||||
return this.s.promiseLibrary.reject(err);
|
||||
}
|
||||
|
||||
options = Object.assign({}, options);
|
||||
|
||||
// Add ignoreUndefined
|
||||
@@ -839,9 +845,11 @@ Collection.prototype.updateMany = function(filter, update, options, callback) {
|
||||
options.ignoreUndefined = this.s.options.ignoreUndefined;
|
||||
}
|
||||
|
||||
const updateManyOperation = new UpdateManyOperation(this, filter, update, options);
|
||||
|
||||
return executeOperation(this.s.topology, updateManyOperation, callback);
|
||||
return executeOperation(
|
||||
this.s.topology,
|
||||
new UpdateManyOperation(this, filter, update, options),
|
||||
callback
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -850,9 +858,10 @@ Collection.prototype.updateMany = function(filter, update, options, callback) {
|
||||
* @param {object} selector The selector for the update operation.
|
||||
* @param {object} update The update operations to be applied to the documents
|
||||
* @param {object} [options] Optional settings.
|
||||
* @param {(number|string)} [options.w] The write concern.
|
||||
* @param {number} [options.wtimeout] The write concern timeout.
|
||||
* @param {boolean} [options.j=false] Specify a journal write concern.
|
||||
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
|
||||
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
|
||||
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
|
||||
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
|
||||
* @param {boolean} [options.upsert=false] Update operation is an upsert.
|
||||
* @param {boolean} [options.multi=false] Update one/all documents with operation.
|
||||
* @param {boolean} [options.bypassDocumentValidation=false] Allow driver to bypass schema validation in MongoDB 3.2 or higher.
|
||||
@@ -906,13 +915,16 @@ Collection.prototype.update = deprecate(function(selector, update, options, call
|
||||
* @param {object} filter The Filter used to select the document to remove
|
||||
* @param {object} [options] Optional settings.
|
||||
* @param {object} [options.collation] Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).
|
||||
* @param {(number|string)} [options.w] The write concern.
|
||||
* @param {number} [options.wtimeout] The write concern timeout.
|
||||
* @param {boolean} [options.j=false] Specify a journal write concern.
|
||||
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
|
||||
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
|
||||
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
|
||||
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
|
||||
* @param {boolean} [options.checkKeys=false] If true, will throw if bson documents start with `$` or include a `.` in any key value
|
||||
* @param {boolean} [options.serializeFunctions=false] Serialize functions on any object.
|
||||
* @param {boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields.
|
||||
* @param {'queryPlanner'|'queryPlannerExtended'|'executionStats'|'allPlansExecution'|boolean} [options.explain] The verbosity mode for the explain output.
|
||||
* @param {ClientSession} [options.session] optional session to use for this operation
|
||||
* @param {string|object} [options.hint] optional index hint for optimizing the filter query
|
||||
* @param {Collection~deleteWriteOpCallback} [callback] The command result callback
|
||||
* @return {Promise} returns Promise if no callback passed
|
||||
*/
|
||||
@@ -939,13 +951,16 @@ Collection.prototype.removeOne = Collection.prototype.deleteOne;
|
||||
* @param {object} filter The Filter used to select the documents to remove
|
||||
* @param {object} [options] Optional settings.
|
||||
* @param {object} [options.collation] Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).
|
||||
* @param {(number|string)} [options.w] The write concern.
|
||||
* @param {number} [options.wtimeout] The write concern timeout.
|
||||
* @param {boolean} [options.j=false] Specify a journal write concern.
|
||||
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
|
||||
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
|
||||
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
|
||||
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
|
||||
* @param {boolean} [options.checkKeys=false] If true, will throw if bson documents start with `$` or include a `.` in any key value
|
||||
* @param {boolean} [options.serializeFunctions=false] Serialize functions on any object.
|
||||
* @param {boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields.
|
||||
* @param {'queryPlanner'|'queryPlannerExtended'|'executionStats'|'allPlansExecution'|boolean} [options.explain] The verbosity mode for the explain output.
|
||||
* @param {ClientSession} [options.session] optional session to use for this operation
|
||||
* @param {string|object} [options.hint] optional index hint for optimizing the filter query
|
||||
* @param {Collection~deleteWriteOpCallback} [callback] The command result callback
|
||||
* @return {Promise} returns Promise if no callback passed
|
||||
*/
|
||||
@@ -972,9 +987,10 @@ Collection.prototype.removeMany = Collection.prototype.deleteMany;
|
||||
* @param {object} selector The selector for the update operation.
|
||||
* @param {object} [options] Optional settings.
|
||||
* @param {object} [options.collation] Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).
|
||||
* @param {(number|string)} [options.w] The write concern.
|
||||
* @param {number} [options.wtimeout] The write concern timeout.
|
||||
* @param {boolean} [options.j=false] Specify a journal write concern.
|
||||
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
|
||||
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
|
||||
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
|
||||
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
|
||||
* @param {boolean} [options.single=false] Removes the first document found.
|
||||
* @param {ClientSession} [options.session] optional session to use for this operation
|
||||
* @param {Collection~writeOpCallback} [callback] The command result callback
|
||||
@@ -1005,9 +1021,10 @@ Collection.prototype.remove = deprecate(function(selector, options, callback) {
|
||||
* @method
|
||||
* @param {object} doc Document to save
|
||||
* @param {object} [options] Optional settings.
|
||||
* @param {(number|string)} [options.w] The write concern.
|
||||
* @param {number} [options.wtimeout] The write concern timeout.
|
||||
* @param {boolean} [options.j=false] Specify a journal write concern.
|
||||
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
|
||||
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
|
||||
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
|
||||
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
|
||||
* @param {ClientSession} [options.session] optional session to use for this operation
|
||||
* @param {Collection~writeOpCallback} [callback] The command result callback
|
||||
* @return {Promise} returns Promise if no callback passed
|
||||
@@ -1051,7 +1068,6 @@ Collection.prototype.save = deprecate(function(doc, options, callback) {
|
||||
* @param {object} [options.fields] **Deprecated** Use `options.projection` instead
|
||||
* @param {number} [options.skip=0] Set to skip N documents ahead in your query (useful for pagination).
|
||||
* @param {Object} [options.hint] Tell the query to use specific indexes in the query. Object of indexes to use, {'_id':1}
|
||||
* @param {boolean} [options.explain=false] Explain the query instead of returning the data.
|
||||
* @param {boolean} [options.snapshot=false] DEPRECATED: Snapshot query.
|
||||
* @param {boolean} [options.timeout=false] Specify if the cursor can timeout.
|
||||
* @param {boolean} [options.tailable=false] Specify if the cursor is tailable.
|
||||
@@ -1066,10 +1082,12 @@ Collection.prototype.save = deprecate(function(doc, options, callback) {
|
||||
* @param {boolean} [options.promoteLongs=true] Promotes Long values to number if they fit inside the 53 bits resolution.
|
||||
* @param {boolean} [options.promoteValues=true] Promotes BSON values to native types where possible, set to false to only receive wrapper types.
|
||||
* @param {boolean} [options.promoteBuffers=false] Promotes Binary BSON values to native Node Buffers.
|
||||
* @param {boolean} [options.bsonRegExp=false] By default, regex returned from MDB will be native to the language. Setting to true will ensure that a BSON.BSONRegExp object is returned.
|
||||
* @param {(ReadPreference|string)} [options.readPreference] The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
|
||||
* @param {boolean} [options.partial=false] Specify if the cursor should return partial results when querying against a sharded system
|
||||
* @param {number} [options.maxTimeMS] Number of milliseconds to wait before aborting the query.
|
||||
* @param {object} [options.collation] Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).
|
||||
* @param {'queryPlanner'|'queryPlannerExtended'|'executionStats'|'allPlansExecution'|boolean} [options.explain] The verbosity mode for the explain output.
|
||||
* @param {ClientSession} [options.session] optional session to use for this operation
|
||||
* @param {Collection~resultCallback} [callback] The command result callback
|
||||
* @return {Promise} returns Promise if no callback passed
|
||||
@@ -1083,7 +1101,7 @@ Collection.prototype.findOne = deprecateOptions(
|
||||
function(query, options, callback) {
|
||||
if (typeof callback === 'object') {
|
||||
// TODO(MAJOR): throw in the future
|
||||
console.warn('Third parameter to `findOne()` must be a callback or undefined');
|
||||
emitWarningOnce('Third parameter to `findOne()` must be a callback or undefined');
|
||||
}
|
||||
|
||||
if (typeof query === 'function') (callback = query), (query = {}), (options = {});
|
||||
@@ -1129,10 +1147,10 @@ Collection.prototype.rename = function(newName, options, callback) {
|
||||
*
|
||||
* @method
|
||||
* @param {object} [options] Optional settings.
|
||||
* @param {WriteConcern} [options.writeConcern] A full WriteConcern object
|
||||
* @param {(number|string)} [options.w] The write concern
|
||||
* @param {number} [options.wtimeout] The write concern timeout
|
||||
* @param {boolean} [options.j] The journal write concern
|
||||
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
|
||||
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
|
||||
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
|
||||
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
|
||||
* @param {ClientSession} [options.session] optional session to use for this operation
|
||||
* @param {Collection~resultCallback} [callback] The results callback
|
||||
* @return {Promise} returns Promise if no callback passed
|
||||
@@ -1191,9 +1209,10 @@ Collection.prototype.isCapped = function(options, callback) {
|
||||
* @method
|
||||
* @param {(string|array|object)} fieldOrSpec Defines the index.
|
||||
* @param {object} [options] Optional settings.
|
||||
* @param {(number|string)} [options.w] The write concern.
|
||||
* @param {number} [options.wtimeout] The write concern timeout.
|
||||
* @param {boolean} [options.j=false] Specify a journal write concern.
|
||||
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
|
||||
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
|
||||
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
|
||||
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
|
||||
* @param {boolean} [options.unique=false] Creates an unique index.
|
||||
* @param {boolean} [options.sparse=false] Creates a sparse index.
|
||||
* @param {boolean} [options.background=false] Creates the index in the background, yielding whenever possible.
|
||||
@@ -1206,6 +1225,7 @@ Collection.prototype.isCapped = function(options, callback) {
|
||||
* @param {object} [options.partialFilterExpression] Creates a partial index based on the given filter object (MongoDB 3.2 or higher)
|
||||
* @param {object} [options.collation] Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).
|
||||
* @param {ClientSession} [options.session] optional session to use for this operation
|
||||
* @param {(number|string)} [options.commitQuorum] (MongoDB 4.4. or higher) Specifies how many data-bearing members of a replica set, including the primary, must complete the index builds successfully before the primary marks the indexes as ready. This option accepts the same values for the "w" field in a write concern plus "votingMembers", which indicates all voting data-bearing nodes.
|
||||
* @param {Collection~resultCallback} [callback] The command result callback
|
||||
* @return {Promise} returns Promise if no callback passed
|
||||
* @example
|
||||
@@ -1232,14 +1252,14 @@ Collection.prototype.createIndex = function(fieldOrSpec, options, callback) {
|
||||
if (typeof options === 'function') (callback = options), (options = {});
|
||||
options = options || {};
|
||||
|
||||
const createIndexOperation = new CreateIndexOperation(
|
||||
this.s.db,
|
||||
const createIndexesOperation = new CreateIndexesOperation(
|
||||
this,
|
||||
this.collectionName,
|
||||
fieldOrSpec,
|
||||
options
|
||||
);
|
||||
|
||||
return executeOperation(this.s.topology, createIndexOperation, callback);
|
||||
return executeOperation(this.s.topology, createIndexesOperation, callback);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -1260,6 +1280,7 @@ Collection.prototype.createIndex = function(fieldOrSpec, options, callback) {
|
||||
* @param {Collection~IndexDefinition[]} indexSpecs An array of index specifications to be created
|
||||
* @param {Object} [options] Optional settings
|
||||
* @param {ClientSession} [options.session] optional session to use for this operation
|
||||
* @param {(number|string)} [options.commitQuorum] (MongoDB 4.4. or higher) Specifies how many data-bearing members of a replica set, including the primary, must complete the index builds successfully before the primary marks the indexes as ready. This option accepts the same values for the "w" field in a write concern plus "votingMembers", which indicates all voting data-bearing nodes.
|
||||
* @param {Collection~resultCallback} [callback] The command result callback
|
||||
* @return {Promise} returns Promise if no callback passed
|
||||
* @example
|
||||
@@ -1284,9 +1305,15 @@ Collection.prototype.createIndexes = function(indexSpecs, options, callback) {
|
||||
if (typeof options === 'function') (callback = options), (options = {});
|
||||
|
||||
options = options ? Object.assign({}, options) : {};
|
||||
|
||||
if (typeof options.maxTimeMS !== 'number') delete options.maxTimeMS;
|
||||
|
||||
const createIndexesOperation = new CreateIndexesOperation(this, indexSpecs, options);
|
||||
const createIndexesOperation = new CreateIndexesOperation(
|
||||
this,
|
||||
this.collectionName,
|
||||
indexSpecs,
|
||||
options
|
||||
);
|
||||
|
||||
return executeOperation(this.s.topology, createIndexesOperation, callback);
|
||||
};
|
||||
@@ -1296,9 +1323,10 @@ Collection.prototype.createIndexes = function(indexSpecs, options, callback) {
|
||||
* @method
|
||||
* @param {string} indexName Name of the index to drop.
|
||||
* @param {object} [options] Optional settings.
|
||||
* @param {(number|string)} [options.w] The write concern.
|
||||
* @param {number} [options.wtimeout] The write concern timeout.
|
||||
* @param {boolean} [options.j=false] Specify a journal write concern.
|
||||
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
|
||||
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
|
||||
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
|
||||
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
|
||||
* @param {ClientSession} [options.session] optional session to use for this operation
|
||||
* @param {number} [options.maxTimeMS] Number of milliseconds to wait before aborting the query.
|
||||
* @param {Collection~resultCallback} [callback] The command result callback
|
||||
@@ -1353,19 +1381,20 @@ Collection.prototype.dropAllIndexes = deprecate(
|
||||
* Reindex all indexes on the collection
|
||||
* Warning: reIndex is a blocking operation (indexes are rebuilt in the foreground) and will be slow for large collections.
|
||||
* @method
|
||||
* @deprecated use db.command instead
|
||||
* @param {Object} [options] Optional settings
|
||||
* @param {ClientSession} [options.session] optional session to use for this operation
|
||||
* @param {Collection~resultCallback} [callback] The command result callback
|
||||
* @return {Promise} returns Promise if no callback passed
|
||||
*/
|
||||
Collection.prototype.reIndex = function(options, callback) {
|
||||
Collection.prototype.reIndex = deprecate(function(options, callback) {
|
||||
if (typeof options === 'function') (callback = options), (options = {});
|
||||
options = options || {};
|
||||
|
||||
const reIndexOperation = new ReIndexOperation(this, options);
|
||||
|
||||
return executeOperation(this.s.topology, reIndexOperation, callback);
|
||||
};
|
||||
}, 'collection.reIndex is deprecated. Use db.command instead.');
|
||||
|
||||
/**
|
||||
* Get the list of all indexes information for the collection.
|
||||
@@ -1393,9 +1422,10 @@ Collection.prototype.listIndexes = function(options) {
|
||||
* @deprecated use createIndexes instead
|
||||
* @param {(string|object)} fieldOrSpec Defines the index.
|
||||
* @param {object} [options] Optional settings.
|
||||
* @param {(number|string)} [options.w] The write concern.
|
||||
* @param {number} [options.wtimeout] The write concern timeout.
|
||||
* @param {boolean} [options.j=false] Specify a journal write concern.
|
||||
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
|
||||
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
|
||||
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
|
||||
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
|
||||
* @param {boolean} [options.unique=false] Creates an unique index.
|
||||
* @param {boolean} [options.sparse=false] Creates a sparse index.
|
||||
* @param {boolean} [options.background=false] Creates the index in the background, yielding whenever possible.
|
||||
@@ -1502,7 +1532,7 @@ Collection.prototype.count = deprecate(function(query, options, callback) {
|
||||
|
||||
return executeOperation(
|
||||
this.s.topology,
|
||||
new EstimatedDocumentCountOperation(this, query, options),
|
||||
new EstimatedDocumentCountOperation(this, Object.assign({ query }, options)),
|
||||
callback
|
||||
);
|
||||
}, 'collection.count is deprecated, and will be removed in a future version.' +
|
||||
@@ -1578,6 +1608,7 @@ Collection.prototype.countDocuments = function(query, options, callback) {
|
||||
* @param {(ReadPreference|string)} [options.readPreference] The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
|
||||
* @param {number} [options.maxTimeMS] Number of milliseconds to wait before aborting the query.
|
||||
* @param {object} [options.collation] Specify collation settings for operation. See {@link https://docs.mongodb.com/manual/reference/command/aggregate|aggregation documentation}.
|
||||
* @param {'queryPlanner'|'queryPlannerExtended'|'executionStats'|'allPlansExecution'|boolean} [options.explain] The verbosity mode for the explain output.
|
||||
* @param {ClientSession} [options.session] optional session to use for this operation
|
||||
* @param {Collection~resultCallback} [callback] The command result callback
|
||||
* @return {Promise} returns Promise if no callback passed
|
||||
@@ -1632,7 +1663,7 @@ Collection.prototype.stats = function(options, callback) {
|
||||
|
||||
/**
|
||||
* @typedef {Object} Collection~findAndModifyWriteOpResult
|
||||
* @property {object} value Document returned from the `findAndModify` command. If no documents were found, `value` will be `null` by default (`returnOriginal: true`), even if a document was upserted; if `returnOriginal` was false, the upserted document will be returned in that case.
|
||||
* @property {object} value Document returned from the `findAndModify` command. If no documents were found, `value` will be `null` by default even if a document was upserted unless `returnDocument` is specified as `'after'`, in which case the upserted document will be returned.
|
||||
* @property {object} lastErrorObject The raw lastErrorObject returned from the command. See {@link https://docs.mongodb.com/manual/reference/command/findAndModify/index.html#lasterrorobject|findAndModify command documentation}.
|
||||
* @property {Number} ok Is 1 if the command executed correctly.
|
||||
*/
|
||||
@@ -1657,6 +1688,7 @@ Collection.prototype.stats = function(options, callback) {
|
||||
* @param {boolean} [options.checkKeys=false] If true, will throw if bson documents start with `$` or include a `.` in any key value
|
||||
* @param {boolean} [options.serializeFunctions=false] Serialize functions on any object.
|
||||
* @param {boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields.
|
||||
* @param {'queryPlanner'|'queryPlannerExtended'|'executionStats'|'allPlansExecution'|boolean} [options.explain] The verbosity mode for the explain output.
|
||||
* @param {ClientSession} [options.session] optional session to use for this operation
|
||||
* @param {Collection~findAndModifyCallback} [callback] The collection result callback
|
||||
* @return {Promise<Collection~findAndModifyWriteOpResultObject>} returns Promise if no callback passed
|
||||
@@ -1665,13 +1697,17 @@ Collection.prototype.findOneAndDelete = function(filter, options, callback) {
|
||||
if (typeof options === 'function') (callback = options), (options = {});
|
||||
options = options || {};
|
||||
|
||||
// Basic validation
|
||||
if (filter == null || typeof filter !== 'object')
|
||||
throw toError('filter parameter must be an object');
|
||||
// Add ignoreUndefined
|
||||
if (this.s.options.ignoreUndefined) {
|
||||
options = Object.assign({}, options);
|
||||
options.ignoreUndefined = this.s.options.ignoreUndefined;
|
||||
}
|
||||
|
||||
const findOneAndDeleteOperation = new FindOneAndDeleteOperation(this, filter, options);
|
||||
|
||||
return executeOperation(this.s.topology, findOneAndDeleteOperation, callback);
|
||||
return executeOperation(
|
||||
this.s.topology,
|
||||
new FindOneAndDeleteOperation(this, filter, options),
|
||||
callback
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -1683,44 +1719,44 @@ Collection.prototype.findOneAndDelete = function(filter, options, callback) {
|
||||
* @param {object} [options] Optional settings.
|
||||
* @param {boolean} [options.bypassDocumentValidation=false] Allow driver to bypass schema validation in MongoDB 3.2 or higher.
|
||||
* @param {object} [options.collation] Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).
|
||||
* @param {string|object} [options.hint] An optional index to use for this operation
|
||||
* @param {number} [options.maxTimeMS] The maximum amount of time to allow the query to run.
|
||||
* @param {object} [options.projection] Limits the fields to return for all matching documents.
|
||||
* @param {object} [options.sort] Determines which document the operation modifies if the query selects multiple documents.
|
||||
* @param {boolean} [options.upsert=false] Upsert the document if it does not exist.
|
||||
* @param {boolean} [options.returnOriginal=true] When false, returns the updated document rather than the original. The default is true.
|
||||
* @param {'before'|'after'} [options.returnDocument='before'] When set to `'after'`, returns the updated document rather than the original. The default is `'before'`.
|
||||
* @param {boolean} [options.returnOriginal=true] **Deprecated** Use `options.returnDocument` instead.
|
||||
* @param {boolean} [options.checkKeys=false] If true, will throw if bson documents start with `$` or include a `.` in any key value
|
||||
* @param {boolean} [options.serializeFunctions=false] Serialize functions on any object.
|
||||
* @param {boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields.
|
||||
* @param {'queryPlanner'|'queryPlannerExtended'|'executionStats'|'allPlansExecution'|boolean} [options.explain] The verbosity mode for the explain output.
|
||||
* @param {ClientSession} [options.session] optional session to use for this operation
|
||||
* @param {Collection~findAndModifyCallback} [callback] The collection result callback
|
||||
* @return {Promise<Collection~findAndModifyWriteOpResultObject>} returns Promise if no callback passed
|
||||
*/
|
||||
Collection.prototype.findOneAndReplace = function(filter, replacement, options, callback) {
|
||||
if (typeof options === 'function') (callback = options), (options = {});
|
||||
options = options || {};
|
||||
Collection.prototype.findOneAndReplace = deprecateOptions(
|
||||
{
|
||||
name: 'collection.findOneAndReplace',
|
||||
deprecatedOptions: ['returnOriginal'],
|
||||
optionsIndex: 2
|
||||
},
|
||||
function(filter, replacement, options, callback) {
|
||||
if (typeof options === 'function') (callback = options), (options = {});
|
||||
options = options || {};
|
||||
|
||||
// Basic validation
|
||||
if (filter == null || typeof filter !== 'object')
|
||||
throw toError('filter parameter must be an object');
|
||||
if (replacement == null || typeof replacement !== 'object')
|
||||
throw toError('replacement parameter must be an object');
|
||||
// Add ignoreUndefined
|
||||
if (this.s.options.ignoreUndefined) {
|
||||
options = Object.assign({}, options);
|
||||
options.ignoreUndefined = this.s.options.ignoreUndefined;
|
||||
}
|
||||
|
||||
// Check that there are no atomic operators
|
||||
const keys = Object.keys(replacement);
|
||||
|
||||
if (keys[0] && keys[0][0] === '$') {
|
||||
throw toError('The replacement document must not contain atomic operators.');
|
||||
return executeOperation(
|
||||
this.s.topology,
|
||||
new FindOneAndReplaceOperation(this, filter, replacement, options),
|
||||
callback
|
||||
);
|
||||
}
|
||||
|
||||
const findOneAndReplaceOperation = new FindOneAndReplaceOperation(
|
||||
this,
|
||||
filter,
|
||||
replacement,
|
||||
options
|
||||
);
|
||||
|
||||
return executeOperation(this.s.topology, findOneAndReplaceOperation, callback);
|
||||
};
|
||||
);
|
||||
|
||||
/**
|
||||
* Find a document and update it in one atomic operation. Requires a write lock for the duration of the operation.
|
||||
@@ -1732,38 +1768,44 @@ Collection.prototype.findOneAndReplace = function(filter, replacement, options,
|
||||
* @param {Array} [options.arrayFilters] optional list of array filters referenced in filtered positional operators
|
||||
* @param {boolean} [options.bypassDocumentValidation=false] Allow driver to bypass schema validation in MongoDB 3.2 or higher.
|
||||
* @param {object} [options.collation] Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).
|
||||
* @param {string|object} [options.hint] An optional index to use for this operation
|
||||
* @param {number} [options.maxTimeMS] The maximum amount of time to allow the query to run.
|
||||
* @param {object} [options.projection] Limits the fields to return for all matching documents.
|
||||
* @param {object} [options.sort] Determines which document the operation modifies if the query selects multiple documents.
|
||||
* @param {boolean} [options.upsert=false] Upsert the document if it does not exist.
|
||||
* @param {boolean} [options.returnOriginal=true] When false, returns the updated document rather than the original. The default is true.
|
||||
* @param {'before'|'after'} [options.returnDocument='before'] When set to `'after'`, returns the updated document rather than the original. The default is `'before'`.
|
||||
* @param {boolean} [options.returnOriginal=true] **Deprecated** Use `options.returnDocument` instead.
|
||||
* @param {boolean} [options.checkKeys=false] If true, will throw if bson documents start with `$` or include a `.` in any key value
|
||||
* @param {boolean} [options.serializeFunctions=false] Serialize functions on any object.
|
||||
* @param {boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields.
|
||||
* @param {ClientSession} [options.session] optional session to use for this operation
|
||||
* @param {'queryPlanner'|'queryPlannerExtended'|'executionStats'|'allPlansExecution'|boolean} [options.explain] The verbosity mode for the explain output.
|
||||
* @param {ClientSession} [options.session] An ptional session to use for this operation
|
||||
* @param {Collection~findAndModifyCallback} [callback] The collection result callback
|
||||
* @return {Promise<Collection~findAndModifyWriteOpResultObject>} returns Promise if no callback passed
|
||||
*/
|
||||
Collection.prototype.findOneAndUpdate = function(filter, update, options, callback) {
|
||||
if (typeof options === 'function') (callback = options), (options = {});
|
||||
options = options || {};
|
||||
Collection.prototype.findOneAndUpdate = deprecateOptions(
|
||||
{
|
||||
name: 'collection.findOneAndUpdate',
|
||||
deprecatedOptions: ['returnOriginal'],
|
||||
optionsIndex: 2
|
||||
},
|
||||
function(filter, update, options, callback) {
|
||||
if (typeof options === 'function') (callback = options), (options = {});
|
||||
options = options || {};
|
||||
|
||||
// Basic validation
|
||||
if (filter == null || typeof filter !== 'object')
|
||||
throw toError('filter parameter must be an object');
|
||||
if (update == null || typeof update !== 'object')
|
||||
throw toError('update parameter must be an object');
|
||||
// Add ignoreUndefined
|
||||
if (this.s.options.ignoreUndefined) {
|
||||
options = Object.assign({}, options);
|
||||
options.ignoreUndefined = this.s.options.ignoreUndefined;
|
||||
}
|
||||
|
||||
const err = checkForAtomicOperators(update);
|
||||
if (err) {
|
||||
if (typeof callback === 'function') return callback(err);
|
||||
return this.s.promiseLibrary.reject(err);
|
||||
return executeOperation(
|
||||
this.s.topology,
|
||||
new FindOneAndUpdateOperation(this, filter, update, options),
|
||||
callback
|
||||
);
|
||||
}
|
||||
|
||||
const findOneAndUpdateOperation = new FindOneAndUpdateOperation(this, filter, update, options);
|
||||
|
||||
return executeOperation(this.s.topology, findOneAndUpdateOperation, callback);
|
||||
};
|
||||
);
|
||||
|
||||
/**
|
||||
* Find and update a document.
|
||||
@@ -1772,9 +1814,10 @@ Collection.prototype.findOneAndUpdate = function(filter, update, options, callba
|
||||
* @param {array} sort If multiple docs match, choose the first one in the specified sort order as the object to manipulate.
|
||||
* @param {object} doc The fields/vals to be updated.
|
||||
* @param {object} [options] Optional settings.
|
||||
* @param {(number|string)} [options.w] The write concern.
|
||||
* @param {number} [options.wtimeout] The write concern timeout.
|
||||
* @param {boolean} [options.j=false] Specify a journal write concern.
|
||||
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
|
||||
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
|
||||
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
|
||||
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
|
||||
* @param {boolean} [options.remove=false] Set to true to remove the object before returning.
|
||||
* @param {boolean} [options.upsert=false] Perform an upsert operation.
|
||||
* @param {boolean} [options.new=false] Set to true if you want to return the modified object rather than the original. Ignored for remove.
|
||||
@@ -1822,9 +1865,10 @@ function _findAndModify(query, sort, doc, options, callback) {
|
||||
* @param {object} query Query object to locate the object to modify.
|
||||
* @param {array} sort If multiple docs match, choose the first one in the specified sort order as the object to manipulate.
|
||||
* @param {object} [options] Optional settings.
|
||||
* @param {(number|string)} [options.w] The write concern.
|
||||
* @param {number} [options.wtimeout] The write concern timeout.
|
||||
* @param {boolean} [options.j=false] Specify a journal write concern.
|
||||
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
|
||||
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
|
||||
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
|
||||
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
|
||||
* @param {ClientSession} [options.session] optional session to use for this operation
|
||||
* @param {Collection~resultCallback} [callback] The command result callback
|
||||
* @return {Promise} returns Promise if no callback passed
|
||||
@@ -1855,7 +1899,6 @@ Collection.prototype.findAndRemove = deprecate(function(query, sort, options, ca
|
||||
* @param {number} [options.batchSize=1000] The number of documents to return per batch. See {@link https://docs.mongodb.com/manual/reference/command/aggregate|aggregation documentation}.
|
||||
* @param {object} [options.cursor] Return the query as cursor, on 2.6 > it returns as a real cursor on pre 2.6 it returns as an emulated cursor.
|
||||
* @param {number} [options.cursor.batchSize=1000] Deprecated. Use `options.batchSize`
|
||||
* @param {boolean} [options.explain=false] Explain returns the aggregation execution plan (requires mongodb 2.6 >).
|
||||
* @param {boolean} [options.allowDiskUse=false] allowDiskUse lets the server know if it can use disk to store temporary results for the aggregation (requires mongodb 2.6 >).
|
||||
* @param {number} [options.maxTimeMS] maxTimeMS specifies a cumulative time limit in milliseconds for processing operations on the cursor. MongoDB interrupts the operation at the earliest following interrupt point.
|
||||
* @param {number} [options.maxAwaitTimeMS] The maximum amount of time for the server to wait on new documents to satisfy a tailable cursor query.
|
||||
@@ -1864,9 +1907,11 @@ Collection.prototype.findAndRemove = deprecate(function(query, sort, options, ca
|
||||
* @param {boolean} [options.promoteLongs=true] Promotes Long values to number if they fit inside the 53 bits resolution.
|
||||
* @param {boolean} [options.promoteValues=true] Promotes BSON values to native types where possible, set to false to only receive wrapper types.
|
||||
* @param {boolean} [options.promoteBuffers=false] Promotes Binary BSON values to native Node Buffers.
|
||||
* @param {object} [options.collation] Specify collation (MongoDB 3.4 or higher) settings for update operation (see 3.4 documentation for available fields).
|
||||
* @param {boolean} [options.bsonRegExp=false] By default, regex returned from MDB will be native to the language. Setting to true will ensure that a BSON.BSONRegExp object is returned.
|
||||
* @param {object} [options.collation] Specify collation settings for operation. See {@link https://docs.mongodb.com/manual/reference/command/aggregate|aggregation documentation}.
|
||||
* @param {string} [options.comment] Add a comment to an aggregation command
|
||||
* @param {string|object} [options.hint] Add an index selection hint to an aggregation command
|
||||
* @param {'queryPlanner'|'queryPlannerExtended'|'executionStats'|'allPlansExecution'|boolean} [options.explain] The verbosity mode for the explain output.
|
||||
* @param {ClientSession} [options.session] optional session to use for this operation
|
||||
* @param {Collection~aggregationCallback} callback The command result callback
|
||||
* @return {(null|AggregationCursor)}
|
||||
@@ -1978,7 +2023,7 @@ Collection.prototype.parallelCollectionScan = deprecate(function(options, callba
|
||||
|
||||
options = Object.assign({}, options);
|
||||
// Ensure we have the right read preference inheritance
|
||||
options.readPreference = resolveReadPreference(this, options);
|
||||
options.readPreference = ReadPreference.resolve(this, options);
|
||||
|
||||
// Add a promiseLibrary
|
||||
options.promiseLibrary = this.s.promiseLibrary;
|
||||
@@ -2009,8 +2054,9 @@ Collection.prototype.parallelCollectionScan = deprecate(function(options, callba
|
||||
* @param {ClientSession} [options.session] optional session to use for this operation
|
||||
* @param {Collection~resultCallback} [callback] The command result callback
|
||||
* @return {Promise} returns Promise if no callback passed
|
||||
* @deprecated See {@link https://docs.mongodb.com/manual/geospatial-queries/|geospatial queries docs} for current geospatial support
|
||||
*/
|
||||
Collection.prototype.geoHaystackSearch = function(x, y, options, callback) {
|
||||
Collection.prototype.geoHaystackSearch = deprecate(function(x, y, options, callback) {
|
||||
const args = Array.prototype.slice.call(arguments, 2);
|
||||
callback = typeof args[args.length - 1] === 'function' ? args.pop() : undefined;
|
||||
options = args.length ? args.shift() || {} : {};
|
||||
@@ -2018,7 +2064,7 @@ Collection.prototype.geoHaystackSearch = function(x, y, options, callback) {
|
||||
const geoHaystackSearchOperation = new GeoHaystackSearchOperation(this, x, y, options);
|
||||
|
||||
return executeOperation(this.s.topology, geoHaystackSearchOperation, callback);
|
||||
};
|
||||
}, 'geoHaystackSearch is deprecated, and will be removed in a future version.');
|
||||
|
||||
/**
|
||||
* Run a group command across a collection
|
||||
@@ -2112,6 +2158,7 @@ Collection.prototype.group = deprecate(function(
|
||||
* @param {boolean} [options.jsMode=false] It is possible to make the execution stay in JS. Provided in MongoDB > 2.0.X.
|
||||
* @param {boolean} [options.verbose=false] Provide statistics on job execution time.
|
||||
* @param {boolean} [options.bypassDocumentValidation=false] Allow driver to bypass schema validation in MongoDB 3.2 or higher.
|
||||
* @param {'queryPlanner'|'queryPlannerExtended'|'executionStats'|'allPlansExecution'|boolean} [options.explain] The verbosity mode for the explain output.
|
||||
* @param {ClientSession} [options.session] optional session to use for this operation
|
||||
* @param {Collection~resultCallback} [callback] The command result callback
|
||||
* @throws {MongoError}
|
||||
@@ -2147,9 +2194,10 @@ Collection.prototype.mapReduce = function(map, reduce, options, callback) {
|
||||
*
|
||||
* @method
|
||||
* @param {object} [options] Optional settings.
|
||||
* @param {(number|string)} [options.w] The write concern.
|
||||
* @param {number} [options.wtimeout] The write concern timeout.
|
||||
* @param {boolean} [options.j=false] Specify a journal write concern.
|
||||
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
|
||||
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
|
||||
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
|
||||
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
|
||||
* @param {boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields.
|
||||
* @param {ClientSession} [options.session] optional session to use for this operation
|
||||
* @return {UnorderedBulkOperation}
|
||||
@@ -2170,12 +2218,12 @@ Collection.prototype.initializeUnorderedBulkOp = function(options) {
|
||||
*
|
||||
* @method
|
||||
* @param {object} [options] Optional settings.
|
||||
* @param {(number|string)} [options.w] The write concern.
|
||||
* @param {number} [options.wtimeout] The write concern timeout.
|
||||
* @param {boolean} [options.j=false] Specify a journal write concern.
|
||||
* @param {(number|string)} [options.w] **Deprecated** The write concern. Use writeConcern instead.
|
||||
* @param {number} [options.wtimeout] **Deprecated** The write concern timeout. Use writeConcern instead.
|
||||
* @param {boolean} [options.j=false] **Deprecated** Specify a journal write concern. Use writeConcern instead.
|
||||
* @param {object|WriteConcern} [options.writeConcern] Specify write concern settings.
|
||||
* @param {ClientSession} [options.session] optional session to use for this operation
|
||||
* @param {boolean} [options.ignoreUndefined=false] Specify if the BSON serializer should ignore undefined fields.
|
||||
* @param {OrderedBulkOperation} callback The command result callback
|
||||
* @return {null}
|
||||
*/
|
||||
Collection.prototype.initializeOrderedBulkOp = function(options) {
|
||||
|
||||
Reference in New Issue
Block a user