This commit is contained in:
2020-08-20 11:44:32 +02:00
parent 4715fc1814
commit 6aceefeb2f
2891 changed files with 11239 additions and 347539 deletions

View File

@@ -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;