Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Db.prototype.dropCollection = function(name, options, callback) {
if (typeof options === 'function') (callback = options), (options = {});
options = options || {};
// Command to execute
const cmd = { drop: name };
// Decorate with write concern
applyWriteConcern(cmd, { db: this }, options);
// options
const opts = Object.assign({}, this.s.options, { readPreference: ReadPreference.PRIMARY });
if (options.session) opts.session = options.session;
return executeOperation(this.s.topology, dropCollection, [this, cmd, opts, callback]);
};
const capabilities = db.s.topology.capabilities();
// Did the user pass in a collation, check if our write server supports it
if (indexes[0].collation && capabilities && !capabilities.commandsTakeCollation) {
// Create a new error
const error = new MongoError('server/primary/mongos does not support collation');
error.code = 67;
// Return the error
return callback(error);
}
// Create command, apply write concern to command
const cmd = applyWriteConcern({ createIndexes: name, indexes }, { db }, options);
// ReadPreference primary
options.readPreference = ReadPreference.PRIMARY;
// Build the command
executeCommand(db, cmd, options, (err, result) => {
if (err) return handleCallback(callback, err, null);
if (result.ok === 0) return handleCallback(callback, toError(result), null);
// Return the indexName for backward compatibility
handleCallback(callback, null, indexName);
});
}
if (indexes[0].collation && capabilities && !capabilities.commandsTakeCollation) {
// Create a new error
var error = new MongoError(f('server/primary/mongos does not support collation'));
error.code = 67;
// Return the error
return callback(error);
}
// Create command, apply write concern to command
var cmd = writeConcern({ createIndexes: name, indexes: indexes }, self, options);
// Decorate command with writeConcern if supported
decorateWithWriteConcern(cmd, self, options);
// ReadPreference primary
options.readPreference = ReadPreference.PRIMARY;
// Build the command
self.command(cmd, options, function(err, result) {
if (err) return handleCallback(callback, err, null);
if (result.ok === 0) return handleCallback(callback, toError(result), null);
// Return the indexName for backward compatibility
handleCallback(callback, null, indexName);
});
};
Collection.prototype.dropIndex = function(indexName, options, callback) {
const args = Array.prototype.slice.call(arguments, 1);
callback = typeof args[args.length - 1] === 'function' ? args.pop() : undefined;
options = args.length ? args.shift() || {} : {};
// Run only against primary
options.readPreference = ReadPreference.PRIMARY;
return executeOperation(this.s.topology, dropIndex, [this, indexName, options, callback]);
};
Collection.prototype.rename = function(newName, options, callback) {
if (typeof options === 'function') (callback = options), (options = {});
options = Object.assign({}, options, { readPreference: ReadPreference.PRIMARY });
return executeOperation(this.s.topology, rename, [this, newName, options, callback]);
};
Collection.prototype.rename = function(newName, options, callback) {
if (typeof options === 'function') (callback = options), (options = {});
options = Object.assign({}, options, { readPreference: ReadPreference.PRIMARY });
return executeOperation(this.s.topology, rename, [this, newName, options, callback]);
};
Collection.prototype.rename = function(newName, options, callback) {
if (typeof options === 'function') (callback = options), (options = {});
options = Object.assign({}, options, { readPreference: ReadPreference.PRIMARY });
return executeOperation(this.s.topology, rename, [this, newName, options, callback]);
};