Skip to content

Commit

Permalink
fix: reintroduce support for 2.6 listIndexes
Browse files Browse the repository at this point in the history
  • Loading branch information
mbroadst authored and daprahamian committed Aug 13, 2019
1 parent 0f38c94 commit c3bfc05
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/operations/list_indexes.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const defineAspects = require('./operation').defineAspects;
const maxWireVersion = require('../core/utils').maxWireVersion;

const LIST_INDEXES_WIRE_VERSION = 3;
const SUPPORTS_FIND_COMMAND = 4;

class ListIndexesOperation extends CommandOperationV2 {
constructor(collection, options) {
Expand All @@ -16,7 +17,8 @@ class ListIndexesOperation extends CommandOperationV2 {
}

execute(server, callback) {
if (maxWireVersion(server) >= LIST_INDEXES_WIRE_VERSION) {
const serverWireVersion = maxWireVersion(server);
if (serverWireVersion >= LIST_INDEXES_WIRE_VERSION) {
const cursor = this.options.batchSize ? { batchSize: this.options.batchSize } : {};
super.executeCommand(
server,
Expand All @@ -29,7 +31,18 @@ class ListIndexesOperation extends CommandOperationV2 {

const systemIndexesNS = this.collectionNamespace.withCollection('system.indexes').toString();
const collectionNS = this.collectionNamespace.toString();
super.executeCommand(server, { find: systemIndexesNS, query: { ns: collectionNS } }, callback);

if (serverWireVersion >= SUPPORTS_FIND_COMMAND) {
super.executeCommand(
server,
{ find: systemIndexesNS, query: { ns: collectionNS } },
callback
);
return;
}

// fall back to running a query
server.query(systemIndexesNS, { query: { ns: collectionNS } }, {}, this.options, callback);
}
}

Expand Down

0 comments on commit c3bfc05

Please sign in to comment.