drop_index.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. 'use strict';
  2. const Aspect = require('./operation').Aspect;
  3. const defineAspects = require('./operation').defineAspects;
  4. const CommandOperation = require('./command');
  5. const applyWriteConcern = require('../utils').applyWriteConcern;
  6. const handleCallback = require('../utils').handleCallback;
  7. class DropIndexOperation extends CommandOperation {
  8. constructor(collection, indexName, options) {
  9. super(collection.s.db, options, collection);
  10. this.collection = collection;
  11. this.indexName = indexName;
  12. }
  13. _buildCommand() {
  14. const collection = this.collection;
  15. const indexName = this.indexName;
  16. const options = this.options;
  17. let cmd = { dropIndexes: collection.collectionName, index: indexName };
  18. // Decorate command with writeConcern if supported
  19. cmd = applyWriteConcern(cmd, { db: collection.s.db, collection }, options);
  20. return cmd;
  21. }
  22. execute(callback) {
  23. // Execute command
  24. super.execute((err, result) => {
  25. if (typeof callback !== 'function') return;
  26. if (err) return handleCallback(callback, err, null);
  27. handleCallback(callback, null, result);
  28. });
  29. }
  30. }
  31. defineAspects(DropIndexOperation, Aspect.WRITE_OPERATION);
  32. module.exports = DropIndexOperation;