gx
chenyc
2025-06-12 7b72ac13a83764a662159d4a49b7fffb90476ecb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
'use strict';
 
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 CommandOperationV2 {
  constructor(collection, options) {
    super(collection, options);
    this.collectionName = collection.collectionName;
  }
 
  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;