re_index.js 1022 B

123456789101112131415161718192021222324252627282930313233
  1. 'use strict';
  2. const Aspect = require('./operation').Aspect;
  3. const defineAspects = require('./operation').defineAspects;
  4. const CommandOperationV2 = require('./command_v2');
  5. const serverType = require('../core/sdam/common').serverType;
  6. const ServerType = require('../core/sdam/common').ServerType;
  7. const MongoError = require('../core').MongoError;
  8. class ReIndexOperation extends CommandOperationV2 {
  9. constructor(collection, options) {
  10. super(collection, options);
  11. this.collectionName = collection.collectionName;
  12. }
  13. execute(server, callback) {
  14. if (serverType(server) !== ServerType.Standalone) {
  15. callback(new MongoError(`reIndex can only be executed on standalone servers.`));
  16. return;
  17. }
  18. super.executeCommand(server, { reIndex: this.collectionName }, (err, result) => {
  19. if (err) {
  20. callback(err);
  21. return;
  22. }
  23. callback(null, !!result.ok);
  24. });
  25. }
  26. }
  27. defineAspects(ReIndexOperation, [Aspect.EXECUTE_WITH_SELECTION]);
  28. module.exports = ReIndexOperation;