list_indexes.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. 'use strict';
  2. const CommandOperationV2 = require('./command_v2');
  3. const Aspect = require('./operation').Aspect;
  4. const defineAspects = require('./operation').defineAspects;
  5. const maxWireVersion = require('../core/utils').maxWireVersion;
  6. const LIST_INDEXES_WIRE_VERSION = 3;
  7. class ListIndexesOperation extends CommandOperationV2 {
  8. constructor(collection, options) {
  9. super(collection, options, { fullResponse: true });
  10. this.collectionNamespace = collection.s.namespace;
  11. }
  12. execute(server, callback) {
  13. const serverWireVersion = maxWireVersion(server);
  14. if (serverWireVersion < LIST_INDEXES_WIRE_VERSION) {
  15. const systemIndexesNS = this.collectionNamespace.withCollection('system.indexes').toString();
  16. const collectionNS = this.collectionNamespace.toString();
  17. server.query(systemIndexesNS, { query: { ns: collectionNS } }, {}, this.options, callback);
  18. return;
  19. }
  20. const cursor = this.options.batchSize ? { batchSize: this.options.batchSize } : {};
  21. super.executeCommand(
  22. server,
  23. { listIndexes: this.collectionNamespace.collection, cursor },
  24. callback
  25. );
  26. }
  27. }
  28. defineAspects(ListIndexesOperation, [
  29. Aspect.READ_OPERATION,
  30. Aspect.RETRYABLE,
  31. Aspect.EXECUTE_WITH_SELECTION
  32. ]);
  33. module.exports = ListIndexesOperation;