@@ -28,7 +28,6 @@ const AggregationCursor = require('./aggregation_cursor');
28
28
const createListener = require ( './operations/db_ops' ) . createListener ;
29
29
const ensureIndex = require ( './operations/db_ops' ) . ensureIndex ;
30
30
const evaluate = require ( './operations/db_ops' ) . evaluate ;
31
- const listCollectionsTransforms = require ( './operations/db_ops' ) . listCollectionsTransforms ;
32
31
const profilingInfo = require ( './operations/db_ops' ) . profilingInfo ;
33
32
const validateDatabaseName = require ( './operations/db_ops' ) . validateDatabaseName ;
34
33
@@ -42,6 +41,7 @@ const DropCollectionOperation = require('./operations/drop').DropCollectionOpera
42
41
const DropDatabaseOperation = require ( './operations/drop' ) . DropDatabaseOperation ;
43
42
const ExecuteDbAdminCommandOperation = require ( './operations/execute_db_admin_command' ) ;
44
43
const IndexInformationOperation = require ( './operations/index_information' ) ;
44
+ const ListCollectionsOperation = require ( './operations/list_collections' ) ;
45
45
const ProfilingLevelOperation = require ( './operations/profiling_level' ) ;
46
46
const RemoveUserOperation = require ( './operations/remove_user' ) ;
47
47
const RenameOperation = require ( './operations/rename' ) ;
@@ -572,72 +572,11 @@ Db.prototype.listCollections = function(filter, options) {
572
572
filter = filter || { } ;
573
573
options = options || { } ;
574
574
575
- // Shallow clone the object
576
- options = Object . assign ( { } , options ) ;
577
- // Set the promise library
578
- options . promiseLibrary = this . s . promiseLibrary ;
579
-
580
- // Ensure valid readPreference
581
- options . readPreference = resolveReadPreference ( this , options ) ;
582
-
583
- // Cursor options
584
- let cursor = options . batchSize ? { batchSize : options . batchSize } : { } ;
585
-
586
- // We have a list collections command
587
- if ( this . serverConfig . capabilities ( ) . hasListCollectionsCommand ) {
588
- const nameOnly = typeof options . nameOnly === 'boolean' ? options . nameOnly : false ;
589
- // Build the command
590
- const command = { listCollections : 1 , filter, cursor, nameOnly } ;
591
- // Set the AggregationCursor constructor
592
- options . cursorFactory = CommandCursor ;
593
- // Create the cursor
594
- cursor = this . s . topology . cursor (
595
- this . s . namespace . withCollection ( '$cmd' ) . toString ( ) ,
596
- command ,
597
- options
598
- ) ;
599
- // Do we have a readPreference, apply it
600
- if ( options . readPreference ) {
601
- cursor . setReadPreference ( options . readPreference ) ;
602
- }
603
- // Return the cursor
604
- return cursor ;
605
- }
606
-
607
- // We cannot use the listCollectionsCommand
608
- if ( ! this . serverConfig . capabilities ( ) . hasListCollectionsCommand ) {
609
- // If we have legacy mode and have not provided a full db name filter it
610
- if (
611
- typeof filter . name === 'string' &&
612
- ! new RegExp ( '^' + this . databaseName + '\\.' ) . test ( filter . name )
613
- ) {
614
- filter = Object . assign ( { } , filter ) ;
615
- filter . name = this . s . namespace . withCollection ( filter . name ) . toString ( ) ;
616
- }
617
- }
618
-
619
- // No filter, filter by current database
620
- if ( filter == null ) {
621
- filter . name = `/${ this . databaseName } /` ;
622
- }
623
-
624
- // Rewrite the filter to use $and to filter out indexes
625
- if ( filter . name ) {
626
- filter = { $and : [ { name : filter . name } , { name : / ^ ( (? ! \$ ) .) * $ / } ] } ;
627
- } else {
628
- filter = { name : / ^ ( (? ! \$ ) .) * $ / } ;
629
- }
630
-
631
- // Return options
632
- const _options = { transforms : listCollectionsTransforms ( this . databaseName ) } ;
633
- // Get the cursor
634
- cursor = this . collection ( CONSTANTS . SYSTEM_NAMESPACE_COLLECTION ) . find ( filter , _options ) ;
635
- // Do we have a readPreference, apply it
636
- if ( options . readPreference ) cursor . setReadPreference ( options . readPreference ) ;
637
- // Set the passed in batch size if one was provided
638
- if ( options . batchSize ) cursor = cursor . batchSize ( options . batchSize ) ;
639
- // We have a fallback mode using legacy systems collections
640
- return cursor ;
575
+ return new CommandCursor (
576
+ this . s . topology ,
577
+ new ListCollectionsOperation ( this , filter , options ) ,
578
+ options
579
+ ) ;
641
580
} ;
642
581
643
582
/**
0 commit comments