@@ -6,6 +6,7 @@ const defineAspects = require('./operation').defineAspects;
6
6
const maxWireVersion = require ( '../core/utils' ) . maxWireVersion ;
7
7
8
8
const LIST_INDEXES_WIRE_VERSION = 3 ;
9
+ const SUPPORTS_FIND_COMMAND = 4 ;
9
10
10
11
class ListIndexesOperation extends CommandOperationV2 {
11
12
constructor ( collection , options ) {
@@ -16,7 +17,8 @@ class ListIndexesOperation extends CommandOperationV2 {
16
17
}
17
18
18
19
execute ( server , callback ) {
19
- if ( maxWireVersion ( server ) >= LIST_INDEXES_WIRE_VERSION ) {
20
+ const serverWireVersion = maxWireVersion ( server ) ;
21
+ if ( serverWireVersion >= LIST_INDEXES_WIRE_VERSION ) {
20
22
const cursor = this . options . batchSize ? { batchSize : this . options . batchSize } : { } ;
21
23
super . executeCommand (
22
24
server ,
@@ -29,7 +31,18 @@ class ListIndexesOperation extends CommandOperationV2 {
29
31
30
32
const systemIndexesNS = this . collectionNamespace . withCollection ( 'system.indexes' ) . toString ( ) ;
31
33
const collectionNS = this . collectionNamespace . toString ( ) ;
32
- super . executeCommand ( server , { find : systemIndexesNS , query : { ns : collectionNS } } , callback ) ;
34
+
35
+ if ( serverWireVersion >= SUPPORTS_FIND_COMMAND ) {
36
+ super . executeCommand (
37
+ server ,
38
+ { find : systemIndexesNS , query : { ns : collectionNS } } ,
39
+ callback
40
+ ) ;
41
+ return ;
42
+ }
43
+
44
+ // fall back to running a query
45
+ server . query ( systemIndexesNS , { query : { ns : collectionNS } } , { } , this . options , callback ) ;
33
46
}
34
47
}
35
48
0 commit comments