Cleanup
This commit is contained in:
28
node_modules/mongodb/lib/operations/db_ops.js
generated
vendored
28
node_modules/mongodb/lib/operations/db_ops.js
generated
vendored
@@ -1,14 +1,15 @@
|
||||
'use strict';
|
||||
|
||||
const MONGODB_ERROR_CODES = require('../error_codes').MONGODB_ERROR_CODES;
|
||||
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;
|
||||
const parseIndexOptions = require('../utils').parseIndexOptions;
|
||||
const ReadPreference = require('../core').ReadPreference;
|
||||
const toError = require('../utils').toError;
|
||||
const extractCommand = require('../command_utils').extractCommand;
|
||||
const CONSTANTS = require('../constants');
|
||||
const MongoDBNamespace = require('../utils').MongoDBNamespace;
|
||||
|
||||
@@ -24,6 +25,7 @@ const debugFields = [
|
||||
'promoteLongs',
|
||||
'promoteValues',
|
||||
'promoteBuffers',
|
||||
'bsonRegExp',
|
||||
'bufferMaxEntries',
|
||||
'numberOfRetries',
|
||||
'retryMiliSeconds',
|
||||
@@ -74,12 +76,12 @@ function createIndex(db, name, fieldOrSpec, options, callback) {
|
||||
* 197 = 'InvalidIndexSpecificationOption' (`_id` with `background: true`)
|
||||
*/
|
||||
if (
|
||||
err.code === 67 ||
|
||||
err.code === 11000 ||
|
||||
err.code === 85 ||
|
||||
err.code === 86 ||
|
||||
err.code === 11600 ||
|
||||
err.code === 197
|
||||
err.code === MONGODB_ERROR_CODES.CannotCreateIndex ||
|
||||
err.code === MONGODB_ERROR_CODES.DuplicateKey ||
|
||||
err.code === MONGODB_ERROR_CODES.IndexOptionsConflict ||
|
||||
err.code === MONGODB_ERROR_CODES.IndexKeySpecsConflict ||
|
||||
err.code === MONGODB_ERROR_CODES.InterruptedAtShutdown ||
|
||||
err.code === MONGODB_ERROR_CODES.InvalidIndexSpecificationOption
|
||||
) {
|
||||
return handleCallback(callback, err, result);
|
||||
}
|
||||
@@ -146,7 +148,9 @@ function ensureIndex(db, name, fieldOrSpec, options, callback) {
|
||||
|
||||
// Check if the index already exists
|
||||
indexInformation(db, name, finalOptions, (err, indexInformation) => {
|
||||
if (err != null && err.code !== 26) return handleCallback(callback, err, null);
|
||||
if (err != null && err.code !== MONGODB_ERROR_CODES.NamespaceNotFound) {
|
||||
return handleCallback(callback, err, null);
|
||||
}
|
||||
// If the index does not exist, create it
|
||||
if (indexInformation == null || !indexInformation[index_name]) {
|
||||
createIndex(db, name, fieldOrSpec, options, callback);
|
||||
@@ -225,17 +229,19 @@ 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())
|
||||
if (db.s.logger.isDebug()) {
|
||||
const extractedCommand = extractCommand(command);
|
||||
db.s.logger.debug(
|
||||
`executing command ${JSON.stringify(
|
||||
command
|
||||
extractedCommand.shouldRedact ? `${extractedCommand.name} details REDACTED` : command
|
||||
)} against ${dbName}.$cmd with options [${JSON.stringify(
|
||||
debugOptions(debugFields, options)
|
||||
)}]`
|
||||
);
|
||||
}
|
||||
|
||||
// Execute command
|
||||
db.s.topology.command(db.s.namespace.withCollection('$cmd'), command, options, (err, result) => {
|
||||
|
||||
Reference in New Issue
Block a user