Changes
This commit is contained in:
23
node_modules/mongodb/lib/operations/collection_ops.js
generated
vendored
23
node_modules/mongodb/lib/operations/collection_ops.js
generated
vendored
@@ -8,13 +8,11 @@ const decorateWithReadConcern = require('../utils').decorateWithReadConcern;
|
||||
const ensureIndexDb = require('./db_ops').ensureIndex;
|
||||
const evaluate = require('./db_ops').evaluate;
|
||||
const executeCommand = require('./db_ops').executeCommand;
|
||||
const resolveReadPreference = require('../utils').resolveReadPreference;
|
||||
const handleCallback = require('../utils').handleCallback;
|
||||
const indexInformationDb = require('./db_ops').indexInformation;
|
||||
const Long = require('../core').BSON.Long;
|
||||
const MongoError = require('../core').MongoError;
|
||||
const ReadPreference = require('../core').ReadPreference;
|
||||
const toError = require('../utils').toError;
|
||||
const insertDocuments = require('./common_functions').insertDocuments;
|
||||
const updateDocuments = require('./common_functions').updateDocuments;
|
||||
|
||||
@@ -52,24 +50,6 @@ const updateDocuments = require('./common_functions').updateDocuments;
|
||||
const groupFunction =
|
||||
'function () {\nvar c = db[ns].find(condition);\nvar map = new Map();\nvar reduce_function = reduce;\n\nwhile (c.hasNext()) {\nvar obj = c.next();\nvar key = {};\n\nfor (var i = 0, len = keys.length; i < len; ++i) {\nvar k = keys[i];\nkey[k] = obj[k];\n}\n\nvar aggObj = map.get(key);\n\nif (aggObj == null) {\nvar newObj = Object.extend({}, key);\naggObj = Object.extend(newObj, initial);\nmap.put(key, aggObj);\n}\n\nreduce_function(obj, aggObj);\n}\n\nreturn { "result": map.values() };\n}';
|
||||
|
||||
// Check the update operation to ensure it has atomic operators.
|
||||
function checkForAtomicOperators(update) {
|
||||
if (Array.isArray(update)) {
|
||||
return update.reduce((err, u) => err || checkForAtomicOperators(u), null);
|
||||
}
|
||||
|
||||
const keys = Object.keys(update);
|
||||
|
||||
// same errors as the server would give for update doc lacking atomic operators
|
||||
if (keys.length === 0) {
|
||||
return toError('The update operation document must contain at least one atomic operator.');
|
||||
}
|
||||
|
||||
if (keys[0][0] !== '$') {
|
||||
return toError('the update operation document must contain atomic operators.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an index on the db and collection.
|
||||
*
|
||||
@@ -188,7 +168,7 @@ function group(coll, keys, condition, initial, reduce, finalize, command, option
|
||||
|
||||
options = Object.assign({}, options);
|
||||
// Ensure we have the right read preference inheritance
|
||||
options.readPreference = resolveReadPreference(coll, options);
|
||||
options.readPreference = ReadPreference.resolve(coll, options);
|
||||
|
||||
// Do we have a readConcern specified
|
||||
decorateWithReadConcern(selector, coll, options);
|
||||
@@ -361,7 +341,6 @@ function save(coll, doc, options, callback) {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
checkForAtomicOperators,
|
||||
createIndex,
|
||||
createIndexes,
|
||||
ensureIndex,
|
||||
|
||||
5
node_modules/mongodb/lib/operations/command.js
generated
vendored
5
node_modules/mongodb/lib/operations/command.js
generated
vendored
@@ -7,7 +7,6 @@ const debugOptions = require('../utils').debugOptions;
|
||||
const handleCallback = require('../utils').handleCallback;
|
||||
const MongoError = require('../core').MongoError;
|
||||
const ReadPreference = require('../core').ReadPreference;
|
||||
const resolveReadPreference = require('../utils').resolveReadPreference;
|
||||
const MongoDBNamespace = require('../utils').MongoDBNamespace;
|
||||
|
||||
const debugFields = [
|
||||
@@ -38,9 +37,9 @@ class CommandOperation extends OperationBase {
|
||||
|
||||
if (!this.hasAspect(Aspect.WRITE_OPERATION)) {
|
||||
if (collection != null) {
|
||||
this.options.readPreference = resolveReadPreference(collection, options);
|
||||
this.options.readPreference = ReadPreference.resolve(collection, options);
|
||||
} else {
|
||||
this.options.readPreference = resolveReadPreference(db, options);
|
||||
this.options.readPreference = ReadPreference.resolve(db, options);
|
||||
}
|
||||
} else {
|
||||
if (collection != null) {
|
||||
|
||||
15
node_modules/mongodb/lib/operations/command_v2.js
generated
vendored
15
node_modules/mongodb/lib/operations/command_v2.js
generated
vendored
@@ -2,12 +2,12 @@
|
||||
|
||||
const Aspect = require('./operation').Aspect;
|
||||
const OperationBase = require('./operation').OperationBase;
|
||||
const resolveReadPreference = require('../utils').resolveReadPreference;
|
||||
const ReadPreference = require('../core').ReadPreference;
|
||||
const ReadConcern = require('../read_concern');
|
||||
const WriteConcern = require('../write_concern');
|
||||
const maxWireVersion = require('../core/utils').maxWireVersion;
|
||||
const commandSupportsReadConcern = require('../core/sessions').commandSupportsReadConcern;
|
||||
const MongoError = require('../error').MongoError;
|
||||
const MongoError = require('../core/error').MongoError;
|
||||
|
||||
const SUPPORTS_WRITE_CONCERN_AND_COLLATION = 5;
|
||||
|
||||
@@ -16,9 +16,10 @@ class CommandOperationV2 extends OperationBase {
|
||||
super(options);
|
||||
|
||||
this.ns = parent.s.namespace.withCollection('$cmd');
|
||||
this.readPreference = resolveReadPreference(parent, this.options);
|
||||
this.readConcern = resolveReadConcern(parent, this.options);
|
||||
this.writeConcern = resolveWriteConcern(parent, this.options);
|
||||
const propertyProvider = this.hasAspect(Aspect.NO_INHERIT_OPTIONS) ? undefined : parent;
|
||||
this.readPreference = ReadPreference.resolve(propertyProvider, this.options);
|
||||
this.readConcern = resolveReadConcern(propertyProvider, this.options);
|
||||
this.writeConcern = resolveWriteConcern(propertyProvider, this.options);
|
||||
this.explain = false;
|
||||
|
||||
if (operationOptions && typeof operationOptions.fullResponse === 'boolean') {
|
||||
@@ -97,11 +98,11 @@ class CommandOperationV2 extends OperationBase {
|
||||
}
|
||||
|
||||
function resolveWriteConcern(parent, options) {
|
||||
return WriteConcern.fromOptions(options) || parent.writeConcern;
|
||||
return WriteConcern.fromOptions(options) || (parent && parent.writeConcern);
|
||||
}
|
||||
|
||||
function resolveReadConcern(parent, options) {
|
||||
return ReadConcern.fromOptions(options) || parent.readConcern;
|
||||
return ReadConcern.fromOptions(options) || (parent && parent.readConcern);
|
||||
}
|
||||
|
||||
module.exports = CommandOperationV2;
|
||||
|
||||
3
node_modules/mongodb/lib/operations/common_functions.js
generated
vendored
3
node_modules/mongodb/lib/operations/common_functions.js
generated
vendored
@@ -297,6 +297,9 @@ function removeDocuments(coll, selector, options, callback) {
|
||||
} else if (finalOptions.retryWrites) {
|
||||
finalOptions.retryWrites = false;
|
||||
}
|
||||
if (options.hint) {
|
||||
op.hint = options.hint;
|
||||
}
|
||||
|
||||
// Have we specified collation
|
||||
try {
|
||||
|
||||
25
node_modules/mongodb/lib/operations/connect.js
generated
vendored
25
node_modules/mongodb/lib/operations/connect.js
generated
vendored
@@ -33,9 +33,11 @@ const legacyParse = deprecate(
|
||||
|
||||
const AUTH_MECHANISM_INTERNAL_MAP = {
|
||||
DEFAULT: 'default',
|
||||
'MONGODB-CR': 'mongocr',
|
||||
PLAIN: 'plain',
|
||||
GSSAPI: 'gssapi',
|
||||
'MONGODB-CR': 'mongocr',
|
||||
'MONGODB-X509': 'x509',
|
||||
'MONGODB-AWS': 'mongodb-aws',
|
||||
'SCRAM-SHA-1': 'scram-sha-1',
|
||||
'SCRAM-SHA-256': 'scram-sha-256'
|
||||
};
|
||||
@@ -66,12 +68,13 @@ const monitoringEvents = [
|
||||
|
||||
const VALID_AUTH_MECHANISMS = new Set([
|
||||
'DEFAULT',
|
||||
'MONGODB-CR',
|
||||
'PLAIN',
|
||||
'GSSAPI',
|
||||
'MONGODB-CR',
|
||||
'MONGODB-X509',
|
||||
'MONGODB-AWS',
|
||||
'SCRAM-SHA-1',
|
||||
'SCRAM-SHA-256',
|
||||
'GSSAPI'
|
||||
'SCRAM-SHA-256'
|
||||
]);
|
||||
|
||||
const validOptionNames = [
|
||||
@@ -151,6 +154,8 @@ const validOptionNames = [
|
||||
'tlsCertificateKeyFilePassword',
|
||||
'minHeartbeatFrequencyMS',
|
||||
'heartbeatFrequencyMS',
|
||||
'directConnection',
|
||||
'appName',
|
||||
|
||||
// CMAP options
|
||||
'maxPoolSize',
|
||||
@@ -644,6 +649,7 @@ function generateCredentials(client, username, password, options) {
|
||||
// authMechanism
|
||||
const authMechanismRaw = options.authMechanism || 'DEFAULT';
|
||||
const authMechanism = authMechanismRaw.toUpperCase();
|
||||
const mechanismProperties = options.authMechanismProperties;
|
||||
|
||||
if (!VALID_AUTH_MECHANISMS.has(authMechanism)) {
|
||||
throw MongoError.create({
|
||||
@@ -652,18 +658,9 @@ function generateCredentials(client, username, password, options) {
|
||||
});
|
||||
}
|
||||
|
||||
if (authMechanism === 'GSSAPI') {
|
||||
return new MongoCredentials({
|
||||
mechanism: process.platform === 'win32' ? 'sspi' : 'gssapi',
|
||||
mechanismProperties: options,
|
||||
source,
|
||||
username,
|
||||
password
|
||||
});
|
||||
}
|
||||
|
||||
return new MongoCredentials({
|
||||
mechanism: AUTH_MECHANISM_INTERNAL_MAP[authMechanism],
|
||||
mechanismProperties,
|
||||
source,
|
||||
username,
|
||||
password
|
||||
|
||||
93
node_modules/mongodb/lib/operations/create_collection.js
generated
vendored
93
node_modules/mongodb/lib/operations/create_collection.js
generated
vendored
@@ -4,13 +4,11 @@ const Aspect = require('./operation').Aspect;
|
||||
const defineAspects = require('./operation').defineAspects;
|
||||
const CommandOperation = require('./command');
|
||||
const applyWriteConcern = require('../utils').applyWriteConcern;
|
||||
const handleCallback = require('../utils').handleCallback;
|
||||
const loadCollection = require('../dynamic_loaders').loadCollection;
|
||||
const MongoError = require('../core').MongoError;
|
||||
const ReadPreference = require('../core').ReadPreference;
|
||||
|
||||
// Filter out any write concern options
|
||||
const illegalCommandFields = [
|
||||
const ILLEGAL_COMMAND_FIELDS = new Set([
|
||||
'w',
|
||||
'wtimeout',
|
||||
'j',
|
||||
@@ -24,12 +22,11 @@ const illegalCommandFields = [
|
||||
'session',
|
||||
'readConcern',
|
||||
'writeConcern'
|
||||
];
|
||||
]);
|
||||
|
||||
class CreateCollectionOperation extends CommandOperation {
|
||||
constructor(db, name, options) {
|
||||
super(db, options);
|
||||
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@@ -37,14 +34,12 @@ class CreateCollectionOperation extends CommandOperation {
|
||||
const name = this.name;
|
||||
const options = this.options;
|
||||
|
||||
// Create collection command
|
||||
const cmd = { create: name };
|
||||
// Add all optional parameters
|
||||
for (let n in options) {
|
||||
if (
|
||||
options[n] != null &&
|
||||
typeof options[n] !== 'function' &&
|
||||
illegalCommandFields.indexOf(n) === -1
|
||||
!ILLEGAL_COMMAND_FIELDS.has(n)
|
||||
) {
|
||||
cmd[n] = options[n];
|
||||
}
|
||||
@@ -57,61 +52,51 @@ class CreateCollectionOperation extends CommandOperation {
|
||||
const db = this.db;
|
||||
const name = this.name;
|
||||
const options = this.options;
|
||||
const Collection = loadCollection();
|
||||
|
||||
let Collection = loadCollection();
|
||||
|
||||
// Did the user destroy the topology
|
||||
if (db.serverConfig && db.serverConfig.isDestroyed()) {
|
||||
return callback(new MongoError('topology was destroyed'));
|
||||
}
|
||||
|
||||
let listCollectionOptions = Object.assign({}, options, { nameOnly: true });
|
||||
let listCollectionOptions = Object.assign({ nameOnly: true, strict: false }, options);
|
||||
listCollectionOptions = applyWriteConcern(listCollectionOptions, { db }, listCollectionOptions);
|
||||
|
||||
// Check if we have the name
|
||||
db.listCollections({ name }, listCollectionOptions)
|
||||
.setReadPreference(ReadPreference.PRIMARY)
|
||||
.toArray((err, collections) => {
|
||||
if (err != null) return handleCallback(callback, err, null);
|
||||
if (collections.length > 0 && listCollectionOptions.strict) {
|
||||
return handleCallback(
|
||||
callback,
|
||||
MongoError.create({
|
||||
message: `Collection ${name} already exists. Currently in strict mode.`,
|
||||
driver: true
|
||||
}),
|
||||
null
|
||||
);
|
||||
} else if (collections.length > 0) {
|
||||
try {
|
||||
return handleCallback(
|
||||
callback,
|
||||
null,
|
||||
new Collection(db, db.s.topology, db.databaseName, name, db.s.pkFactory, options)
|
||||
);
|
||||
} catch (err) {
|
||||
return handleCallback(callback, err);
|
||||
}
|
||||
}
|
||||
function done(err) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
// Execute command
|
||||
super.execute(err => {
|
||||
if (err) return handleCallback(callback, err);
|
||||
try {
|
||||
callback(
|
||||
null,
|
||||
new Collection(db, db.s.topology, db.databaseName, name, db.s.pkFactory, options)
|
||||
);
|
||||
} catch (err) {
|
||||
callback(err);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
return handleCallback(
|
||||
callback,
|
||||
null,
|
||||
new Collection(db, db.s.topology, db.databaseName, name, db.s.pkFactory, options)
|
||||
);
|
||||
} catch (err) {
|
||||
return handleCallback(callback, err);
|
||||
const strictMode = listCollectionOptions.strict;
|
||||
if (strictMode) {
|
||||
db.listCollections({ name }, listCollectionOptions)
|
||||
.setReadPreference(ReadPreference.PRIMARY)
|
||||
.toArray((err, collections) => {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (collections.length > 0) {
|
||||
return callback(
|
||||
new MongoError(`Collection ${name} already exists. Currently in strict mode.`)
|
||||
);
|
||||
}
|
||||
|
||||
super.execute(done);
|
||||
});
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// otherwise just execute the command
|
||||
super.execute(done);
|
||||
}
|
||||
}
|
||||
|
||||
defineAspects(CreateCollectionOperation, Aspect.WRITE_OPERATION);
|
||||
|
||||
module.exports = CreateCollectionOperation;
|
||||
|
||||
124
node_modules/mongodb/lib/operations/create_indexes.js
generated
vendored
124
node_modules/mongodb/lib/operations/create_indexes.js
generated
vendored
@@ -2,60 +2,116 @@
|
||||
|
||||
const Aspect = require('./operation').Aspect;
|
||||
const defineAspects = require('./operation').defineAspects;
|
||||
const OperationBase = require('./operation').OperationBase;
|
||||
const executeCommand = require('./db_ops').executeCommand;
|
||||
const CommandOperationV2 = require('./command_v2');
|
||||
const MongoError = require('../core').MongoError;
|
||||
const ReadPreference = require('../core').ReadPreference;
|
||||
const parseIndexOptions = require('../utils').parseIndexOptions;
|
||||
const maxWireVersion = require('../core/utils').maxWireVersion;
|
||||
|
||||
class CreateIndexesOperation extends OperationBase {
|
||||
constructor(collection, indexSpecs, options) {
|
||||
super(options);
|
||||
const validIndexOptions = new Set([
|
||||
'unique',
|
||||
'partialFilterExpression',
|
||||
'sparse',
|
||||
'background',
|
||||
'expireAfterSeconds',
|
||||
'storageEngine',
|
||||
'collation',
|
||||
'bucketSize'
|
||||
]);
|
||||
|
||||
class CreateIndexesOperation extends CommandOperationV2 {
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
constructor(parent, collection, indexes, options) {
|
||||
super(parent, options);
|
||||
this.collection = collection;
|
||||
this.indexSpecs = indexSpecs;
|
||||
|
||||
// createIndex can be called with a variety of styles:
|
||||
// coll.createIndex('a');
|
||||
// coll.createIndex({ a: 1 });
|
||||
// coll.createIndex([['a', 1]]);
|
||||
// createIndexes is always called with an array of index spec objects
|
||||
if (!Array.isArray(indexes) || Array.isArray(indexes[0])) {
|
||||
this.onlyReturnNameOfCreatedIndex = true;
|
||||
// TODO: remove in v4 (breaking change); make createIndex return full response as createIndexes does
|
||||
|
||||
const indexParameters = parseIndexOptions(indexes);
|
||||
// Generate the index name
|
||||
const name = typeof options.name === 'string' ? options.name : indexParameters.name;
|
||||
// Set up the index
|
||||
const indexSpec = { name, key: indexParameters.fieldHash };
|
||||
// merge valid index options into the index spec
|
||||
for (let optionName in options) {
|
||||
if (validIndexOptions.has(optionName)) {
|
||||
indexSpec[optionName] = options[optionName];
|
||||
}
|
||||
}
|
||||
this.indexes = [indexSpec];
|
||||
return;
|
||||
}
|
||||
|
||||
this.indexes = indexes;
|
||||
}
|
||||
|
||||
execute(callback) {
|
||||
const coll = this.collection;
|
||||
const indexSpecs = this.indexSpecs;
|
||||
let options = this.options;
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
execute(server, callback) {
|
||||
const options = this.options;
|
||||
const indexes = this.indexes;
|
||||
|
||||
const capabilities = coll.s.topology.capabilities();
|
||||
const serverWireVersion = maxWireVersion(server);
|
||||
|
||||
// Ensure we generate the correct name if the parameter is not set
|
||||
for (let i = 0; i < indexSpecs.length; i++) {
|
||||
if (indexSpecs[i].name == null) {
|
||||
for (let i = 0; i < indexes.length; i++) {
|
||||
// Did the user pass in a collation, check if our write server supports it
|
||||
if (indexes[i].collation && serverWireVersion < 5) {
|
||||
callback(
|
||||
new MongoError(
|
||||
`Server ${server.name}, which reports wire version ${serverWireVersion}, does not support collation`
|
||||
)
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (indexes[i].name == null) {
|
||||
const keys = [];
|
||||
|
||||
// Did the user pass in a collation, check if our write server supports it
|
||||
if (indexSpecs[i].collation && capabilities && !capabilities.commandsTakeCollation) {
|
||||
return callback(new MongoError('server/primary/mongos does not support collation'));
|
||||
}
|
||||
|
||||
for (let name in indexSpecs[i].key) {
|
||||
keys.push(`${name}_${indexSpecs[i].key[name]}`);
|
||||
for (let name in indexes[i].key) {
|
||||
keys.push(`${name}_${indexes[i].key[name]}`);
|
||||
}
|
||||
|
||||
// Set the name
|
||||
indexSpecs[i].name = keys.join('_');
|
||||
indexes[i].name = keys.join('_');
|
||||
}
|
||||
}
|
||||
|
||||
options = Object.assign({}, options, { readPreference: ReadPreference.PRIMARY });
|
||||
const cmd = { createIndexes: this.collection, indexes };
|
||||
|
||||
// Execute the index
|
||||
executeCommand(
|
||||
coll.s.db,
|
||||
{
|
||||
createIndexes: coll.collectionName,
|
||||
indexes: indexSpecs
|
||||
},
|
||||
options,
|
||||
callback
|
||||
);
|
||||
if (options.commitQuorum != null) {
|
||||
if (serverWireVersion < 9) {
|
||||
callback(
|
||||
new MongoError('`commitQuorum` option for `createIndexes` not supported on servers < 4.4')
|
||||
);
|
||||
return;
|
||||
}
|
||||
cmd.commitQuorum = options.commitQuorum;
|
||||
}
|
||||
|
||||
// collation is set on each index, it should not be defined at the root
|
||||
this.options.collation = undefined;
|
||||
|
||||
super.executeCommand(server, cmd, (err, result) => {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
|
||||
callback(null, this.onlyReturnNameOfCreatedIndex ? indexes[0].name : result);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
defineAspects(CreateIndexesOperation, Aspect.WRITE_OPERATION);
|
||||
defineAspects(CreateIndexesOperation, [Aspect.WRITE_OPERATION, Aspect.EXECUTE_WITH_SELECTION]);
|
||||
|
||||
module.exports = CreateIndexesOperation;
|
||||
|
||||
3
node_modules/mongodb/lib/operations/db_ops.js
generated
vendored
3
node_modules/mongodb/lib/operations/db_ops.js
generated
vendored
@@ -2,7 +2,6 @@
|
||||
|
||||
const applyWriteConcern = require('../utils').applyWriteConcern;
|
||||
const Code = require('../core').BSON.Code;
|
||||
const resolveReadPreference = require('../utils').resolveReadPreference;
|
||||
const debugOptions = require('../utils').debugOptions;
|
||||
const handleCallback = require('../utils').handleCallback;
|
||||
const MongoError = require('../core').MongoError;
|
||||
@@ -225,7 +224,7 @@ function executeCommand(db, command, options, callback) {
|
||||
const dbName = options.dbName || options.authdb || db.databaseName;
|
||||
|
||||
// Convert the readPreference if its not a write
|
||||
options.readPreference = resolveReadPreference(db, options);
|
||||
options.readPreference = ReadPreference.resolve(db, options);
|
||||
|
||||
// Debug information
|
||||
if (db.s.logger.isDebug())
|
||||
|
||||
12
node_modules/mongodb/lib/operations/find.js
generated
vendored
12
node_modules/mongodb/lib/operations/find.js
generated
vendored
@@ -3,7 +3,9 @@
|
||||
const OperationBase = require('./operation').OperationBase;
|
||||
const Aspect = require('./operation').Aspect;
|
||||
const defineAspects = require('./operation').defineAspects;
|
||||
const resolveReadPreference = require('../utils').resolveReadPreference;
|
||||
const ReadPreference = require('../core').ReadPreference;
|
||||
const maxWireVersion = require('../core/utils').maxWireVersion;
|
||||
const MongoError = require('../core/error').MongoError;
|
||||
|
||||
class FindOperation extends OperationBase {
|
||||
constructor(collection, ns, command, options) {
|
||||
@@ -11,16 +13,20 @@ class FindOperation extends OperationBase {
|
||||
|
||||
this.ns = ns;
|
||||
this.cmd = command;
|
||||
this.readPreference = resolveReadPreference(collection, this.options);
|
||||
this.readPreference = ReadPreference.resolve(collection, this.options);
|
||||
}
|
||||
|
||||
execute(server, callback) {
|
||||
// copied from `CommandOperationV2`, to be subclassed in the future
|
||||
this.server = server;
|
||||
|
||||
const cursorState = this.cursorState || {};
|
||||
if (typeof this.cmd.allowDiskUse !== 'undefined' && maxWireVersion(server) < 4) {
|
||||
callback(new MongoError('The `allowDiskUse` option is not supported on MongoDB < 3.2'));
|
||||
return;
|
||||
}
|
||||
|
||||
// TOOD: use `MongoDBNamespace` through and through
|
||||
const cursorState = this.cursorState || {};
|
||||
server.query(this.ns.toString(), this.cmd, cursorState, this.options, callback);
|
||||
}
|
||||
}
|
||||
|
||||
17
node_modules/mongodb/lib/operations/find_and_modify.js
generated
vendored
17
node_modules/mongodb/lib/operations/find_and_modify.js
generated
vendored
@@ -8,6 +8,8 @@ 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;
|
||||
|
||||
class FindAndModifyOperation extends OperationBase {
|
||||
constructor(collection, query, sort, doc, options) {
|
||||
@@ -86,6 +88,21 @@ 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;
|
||||
}
|
||||
|
||||
// Execute the command
|
||||
executeCommand(coll.s.db, queryObject, options, (err, result) => {
|
||||
if (err) return handleCallback(callback, err, null);
|
||||
|
||||
5
node_modules/mongodb/lib/operations/find_one_and_delete.js
generated
vendored
5
node_modules/mongodb/lib/operations/find_one_and_delete.js
generated
vendored
@@ -9,6 +9,11 @@ class FindOneAndDeleteOperation extends FindAndModifyOperation {
|
||||
finalOptions.fields = options.projection;
|
||||
finalOptions.remove = true;
|
||||
|
||||
// Basic validation
|
||||
if (filter == null || typeof filter !== 'object') {
|
||||
throw new TypeError('Filter parameter must be an object');
|
||||
}
|
||||
|
||||
super(collection, filter, finalOptions.sort, null, finalOptions);
|
||||
}
|
||||
}
|
||||
|
||||
13
node_modules/mongodb/lib/operations/find_one_and_replace.js
generated
vendored
13
node_modules/mongodb/lib/operations/find_one_and_replace.js
generated
vendored
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const FindAndModifyOperation = require('./find_and_modify');
|
||||
const hasAtomicOperators = require('../utils').hasAtomicOperators;
|
||||
|
||||
class FindOneAndReplaceOperation extends FindAndModifyOperation {
|
||||
constructor(collection, filter, replacement, options) {
|
||||
@@ -11,6 +12,18 @@ class FindOneAndReplaceOperation extends FindAndModifyOperation {
|
||||
finalOptions.new = options.returnOriginal !== void 0 ? !options.returnOriginal : false;
|
||||
finalOptions.upsert = options.upsert !== void 0 ? !!options.upsert : false;
|
||||
|
||||
if (filter == null || typeof filter !== 'object') {
|
||||
throw new TypeError('Filter parameter must be an object');
|
||||
}
|
||||
|
||||
if (replacement == null || typeof replacement !== 'object') {
|
||||
throw new TypeError('Replacement parameter must be an object');
|
||||
}
|
||||
|
||||
if (hasAtomicOperators(replacement)) {
|
||||
throw new TypeError('Replacement document must not contain atomic operators');
|
||||
}
|
||||
|
||||
super(collection, filter, finalOptions.sort, replacement, finalOptions);
|
||||
}
|
||||
}
|
||||
|
||||
13
node_modules/mongodb/lib/operations/find_one_and_update.js
generated
vendored
13
node_modules/mongodb/lib/operations/find_one_and_update.js
generated
vendored
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const FindAndModifyOperation = require('./find_and_modify');
|
||||
const hasAtomicOperators = require('../utils').hasAtomicOperators;
|
||||
|
||||
class FindOneAndUpdateOperation extends FindAndModifyOperation {
|
||||
constructor(collection, filter, update, options) {
|
||||
@@ -12,6 +13,18 @@ class FindOneAndUpdateOperation extends FindAndModifyOperation {
|
||||
typeof options.returnOriginal === 'boolean' ? !options.returnOriginal : false;
|
||||
finalOptions.upsert = typeof options.upsert === 'boolean' ? options.upsert : false;
|
||||
|
||||
if (filter == null || typeof filter !== 'object') {
|
||||
throw new TypeError('Filter parameter must be an object');
|
||||
}
|
||||
|
||||
if (update == null || typeof update !== 'object') {
|
||||
throw new TypeError('Update parameter must be an object');
|
||||
}
|
||||
|
||||
if (!hasAtomicOperators(update)) {
|
||||
throw new TypeError('Update document requires atomic operators');
|
||||
}
|
||||
|
||||
super(collection, filter, finalOptions.sort, update, finalOptions);
|
||||
}
|
||||
}
|
||||
|
||||
4
node_modules/mongodb/lib/operations/geo_haystack_search.js
generated
vendored
4
node_modules/mongodb/lib/operations/geo_haystack_search.js
generated
vendored
@@ -7,7 +7,7 @@ const decorateCommand = require('../utils').decorateCommand;
|
||||
const decorateWithReadConcern = require('../utils').decorateWithReadConcern;
|
||||
const executeCommand = require('./db_ops').executeCommand;
|
||||
const handleCallback = require('../utils').handleCallback;
|
||||
const resolveReadPreference = require('../utils').resolveReadPreference;
|
||||
const ReadPreference = require('../core').ReadPreference;
|
||||
const toError = require('../utils').toError;
|
||||
|
||||
/**
|
||||
@@ -58,7 +58,7 @@ class GeoHaystackSearchOperation extends OperationBase {
|
||||
|
||||
options = Object.assign({}, options);
|
||||
// Ensure we have the right read preference inheritance
|
||||
options.readPreference = resolveReadPreference(coll, options);
|
||||
options.readPreference = ReadPreference.resolve(coll, options);
|
||||
|
||||
// Do we have a readConcern specified
|
||||
decorateWithReadConcern(commandObject, coll, options);
|
||||
|
||||
6
node_modules/mongodb/lib/operations/map_reduce.js
generated
vendored
6
node_modules/mongodb/lib/operations/map_reduce.js
generated
vendored
@@ -9,7 +9,7 @@ const handleCallback = require('../utils').handleCallback;
|
||||
const isObject = require('../utils').isObject;
|
||||
const loadDb = require('../dynamic_loaders').loadDb;
|
||||
const OperationBase = require('./operation').OperationBase;
|
||||
const resolveReadPreference = require('../utils').resolveReadPreference;
|
||||
const ReadPreference = require('../core').ReadPreference;
|
||||
const toError = require('../utils').toError;
|
||||
|
||||
const exclusionList = [
|
||||
@@ -60,7 +60,7 @@ class MapReduceOperation extends OperationBase {
|
||||
let options = this.options;
|
||||
|
||||
const mapCommandHash = {
|
||||
mapreduce: coll.collectionName,
|
||||
mapReduce: coll.collectionName,
|
||||
map: map,
|
||||
reduce: reduce
|
||||
};
|
||||
@@ -80,7 +80,7 @@ class MapReduceOperation extends OperationBase {
|
||||
options = Object.assign({}, options);
|
||||
|
||||
// Ensure we have the right read preference inheritance
|
||||
options.readPreference = resolveReadPreference(coll, options);
|
||||
options.readPreference = ReadPreference.resolve(coll, options);
|
||||
|
||||
// If we have a read preference and inline is not set as output fail hard
|
||||
if (
|
||||
|
||||
3
node_modules/mongodb/lib/operations/operation.js
generated
vendored
3
node_modules/mongodb/lib/operations/operation.js
generated
vendored
@@ -4,7 +4,8 @@ const Aspect = {
|
||||
READ_OPERATION: Symbol('READ_OPERATION'),
|
||||
WRITE_OPERATION: Symbol('WRITE_OPERATION'),
|
||||
RETRYABLE: Symbol('RETRYABLE'),
|
||||
EXECUTE_WITH_SELECTION: Symbol('EXECUTE_WITH_SELECTION')
|
||||
EXECUTE_WITH_SELECTION: Symbol('EXECUTE_WITH_SELECTION'),
|
||||
NO_INHERIT_OPTIONS: Symbol('NO_INHERIT_OPTIONS')
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
39
node_modules/mongodb/lib/operations/re_index.js
generated
vendored
39
node_modules/mongodb/lib/operations/re_index.js
generated
vendored
@@ -1,28 +1,33 @@
|
||||
'use strict';
|
||||
|
||||
const CommandOperation = require('./command');
|
||||
const handleCallback = require('../utils').handleCallback;
|
||||
const Aspect = require('./operation').Aspect;
|
||||
const defineAspects = require('./operation').defineAspects;
|
||||
const CommandOperationV2 = require('./command_v2');
|
||||
const serverType = require('../core/sdam/common').serverType;
|
||||
const ServerType = require('../core/sdam/common').ServerType;
|
||||
const MongoError = require('../core').MongoError;
|
||||
|
||||
class ReIndexOperation extends CommandOperation {
|
||||
class ReIndexOperation extends CommandOperationV2 {
|
||||
constructor(collection, options) {
|
||||
super(collection.s.db, options, collection);
|
||||
super(collection, options);
|
||||
this.collectionName = collection.collectionName;
|
||||
}
|
||||
|
||||
_buildCommand() {
|
||||
const collection = this.collection;
|
||||
|
||||
const cmd = { reIndex: collection.collectionName };
|
||||
|
||||
return cmd;
|
||||
}
|
||||
|
||||
execute(callback) {
|
||||
super.execute((err, result) => {
|
||||
if (callback == null) return;
|
||||
if (err) return handleCallback(callback, err, null);
|
||||
handleCallback(callback, null, result.ok ? true : false);
|
||||
execute(server, callback) {
|
||||
if (serverType(server) !== ServerType.Standalone) {
|
||||
callback(new MongoError(`reIndex can only be executed on standalone servers.`));
|
||||
return;
|
||||
}
|
||||
super.executeCommand(server, { reIndex: this.collectionName }, (err, result) => {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
callback(null, !!result.ok);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
defineAspects(ReIndexOperation, [Aspect.EXECUTE_WITH_SELECTION]);
|
||||
|
||||
module.exports = ReIndexOperation;
|
||||
|
||||
15
node_modules/mongodb/lib/operations/replace_one.js
generated
vendored
15
node_modules/mongodb/lib/operations/replace_one.js
generated
vendored
@@ -2,27 +2,34 @@
|
||||
|
||||
const OperationBase = require('./operation').OperationBase;
|
||||
const updateDocuments = require('./common_functions').updateDocuments;
|
||||
const hasAtomicOperators = require('../utils').hasAtomicOperators;
|
||||
|
||||
class ReplaceOneOperation extends OperationBase {
|
||||
constructor(collection, filter, doc, options) {
|
||||
constructor(collection, filter, replacement, options) {
|
||||
super(options);
|
||||
|
||||
if (hasAtomicOperators(replacement)) {
|
||||
throw new TypeError('Replacement document must not contain atomic operators');
|
||||
}
|
||||
|
||||
this.collection = collection;
|
||||
this.filter = filter;
|
||||
this.doc = doc;
|
||||
this.replacement = replacement;
|
||||
}
|
||||
|
||||
execute(callback) {
|
||||
const coll = this.collection;
|
||||
const filter = this.filter;
|
||||
const doc = this.doc;
|
||||
const replacement = this.replacement;
|
||||
const options = this.options;
|
||||
|
||||
// Set single document update
|
||||
options.multi = false;
|
||||
|
||||
// Execute update
|
||||
updateDocuments(coll, filter, doc, options, (err, r) => replaceCallback(err, r, doc, callback));
|
||||
updateDocuments(coll, filter, replacement, options, (err, r) =>
|
||||
replaceCallback(err, r, replacement, callback)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
5
node_modules/mongodb/lib/operations/update_many.js
generated
vendored
5
node_modules/mongodb/lib/operations/update_many.js
generated
vendored
@@ -3,11 +3,16 @@
|
||||
const OperationBase = require('./operation').OperationBase;
|
||||
const updateCallback = require('./common_functions').updateCallback;
|
||||
const updateDocuments = require('./common_functions').updateDocuments;
|
||||
const hasAtomicOperators = require('../utils').hasAtomicOperators;
|
||||
|
||||
class UpdateManyOperation extends OperationBase {
|
||||
constructor(collection, filter, update, options) {
|
||||
super(options);
|
||||
|
||||
if (!hasAtomicOperators(update)) {
|
||||
throw new TypeError('Update document requires atomic operators');
|
||||
}
|
||||
|
||||
this.collection = collection;
|
||||
this.filter = filter;
|
||||
this.update = update;
|
||||
|
||||
5
node_modules/mongodb/lib/operations/update_one.js
generated
vendored
5
node_modules/mongodb/lib/operations/update_one.js
generated
vendored
@@ -2,11 +2,16 @@
|
||||
|
||||
const OperationBase = require('./operation').OperationBase;
|
||||
const updateDocuments = require('./common_functions').updateDocuments;
|
||||
const hasAtomicOperators = require('../utils').hasAtomicOperators;
|
||||
|
||||
class UpdateOneOperation extends OperationBase {
|
||||
constructor(collection, filter, update, options) {
|
||||
super(options);
|
||||
|
||||
if (!hasAtomicOperators(update)) {
|
||||
throw new TypeError('Update document requires atomic operators');
|
||||
}
|
||||
|
||||
this.collection = collection;
|
||||
this.filter = filter;
|
||||
this.update = update;
|
||||
|
||||
3
node_modules/mongodb/lib/operations/validate_collection.js
generated
vendored
3
node_modules/mongodb/lib/operations/validate_collection.js
generated
vendored
@@ -14,8 +14,7 @@ class ValidateCollectionOperation extends CommandOperation {
|
||||
}
|
||||
|
||||
super(admin.s.db, options, null, command);
|
||||
|
||||
this.collectionName;
|
||||
this.collectionName = collectionName;
|
||||
}
|
||||
|
||||
execute(callback) {
|
||||
|
||||
Reference in New Issue
Block a user