Cleanup
This commit is contained in:
32
node_modules/mongodb/lib/operations/find_and_modify.js
generated
vendored
32
node_modules/mongodb/lib/operations/find_and_modify.js
generated
vendored
@@ -8,6 +8,11 @@ const executeCommand = require('./db_ops').executeCommand;
|
||||
const formattedOrderClause = require('../utils').formattedOrderClause;
|
||||
const handleCallback = require('../utils').handleCallback;
|
||||
const ReadPreference = require('../core').ReadPreference;
|
||||
const maxWireVersion = require('../core/utils').maxWireVersion;
|
||||
const MongoError = require('../error').MongoError;
|
||||
const Aspect = require('./operation').Aspect;
|
||||
const defineAspects = require('./operation').defineAspects;
|
||||
const decorateWithExplain = require('../utils').decorateWithExplain;
|
||||
|
||||
class FindAndModifyOperation extends OperationBase {
|
||||
constructor(collection, query, sort, doc, options) {
|
||||
@@ -27,7 +32,7 @@ class FindAndModifyOperation extends OperationBase {
|
||||
let options = this.options;
|
||||
|
||||
// Create findAndModify command object
|
||||
const queryObject = {
|
||||
let queryObject = {
|
||||
findAndModify: coll.collectionName,
|
||||
query: query
|
||||
};
|
||||
@@ -86,6 +91,29 @@ class FindAndModifyOperation extends OperationBase {
|
||||
return callback(err, null);
|
||||
}
|
||||
|
||||
if (options.hint) {
|
||||
// TODO: once this method becomes a CommandOperationV2 we will have the server
|
||||
// in place to check.
|
||||
const unacknowledgedWrite = options.writeConcern && options.writeConcern.w === 0;
|
||||
if (unacknowledgedWrite || maxWireVersion(coll.s.topology) < 8) {
|
||||
callback(
|
||||
new MongoError('The current topology does not support a hint on findAndModify commands')
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
queryObject.hint = options.hint;
|
||||
}
|
||||
|
||||
if (this.explain) {
|
||||
if (maxWireVersion(coll.s.topology) < 4) {
|
||||
callback(new MongoError(`server does not support explain on findAndModify`));
|
||||
return;
|
||||
}
|
||||
queryObject = decorateWithExplain(queryObject, this.explain);
|
||||
}
|
||||
|
||||
// Execute the command
|
||||
executeCommand(coll.s.db, queryObject, options, (err, result) => {
|
||||
if (err) return handleCallback(callback, err, null);
|
||||
@@ -95,4 +123,6 @@ class FindAndModifyOperation extends OperationBase {
|
||||
}
|
||||
}
|
||||
|
||||
defineAspects(FindAndModifyOperation, [Aspect.EXPLAINABLE]);
|
||||
|
||||
module.exports = FindAndModifyOperation;
|
||||
|
||||
Reference in New Issue
Block a user