@@ -455,8 +455,10 @@ Db.prototype.collection = function(name, options, callback) {
455
455
return callback ( new MongoError ( 'topology was destroyed' ) ) ;
456
456
}
457
457
458
+ const listCollectionOptions = Object . assign ( { } , options , { nameOnly : true } ) ;
459
+
458
460
// Strict mode
459
- this . listCollections ( { name : name } , options ) . toArray ( function ( err , collections ) {
461
+ this . listCollections ( { name : name } , listCollectionOptions ) . toArray ( function ( err , collections ) {
460
462
if ( err != null ) return handleCallback ( callback , err , null ) ;
461
463
if ( collections . length === 0 )
462
464
return handleCallback (
@@ -486,9 +488,11 @@ var createCollection = function(self, name, options, callback) {
486
488
return callback ( new MongoError ( 'topology was destroyed' ) ) ;
487
489
}
488
490
491
+ const listCollectionOptions = Object . assign ( { } , finalOptions , { nameOnly : true } ) ;
492
+
489
493
// Check if we have the name
490
494
self
491
- . listCollections ( { name : name } , finalOptions )
495
+ . listCollections ( { name : name } , listCollectionOptions )
492
496
. setReadPreference ( ReadPreference . PRIMARY )
493
497
. toArray ( function ( err , collections ) {
494
498
if ( err != null ) return handleCallback ( callback , err , null ) ;
@@ -653,6 +657,7 @@ var listCollectionsTranforms = function(databaseName) {
653
657
* @method
654
658
* @param {object } [filter={}] Query to filter collections by
655
659
* @param {object } [options=null] Optional settings.
660
+ * @param {boolean } [options.nameOnly=false] Since 4.0: If true, will only return the collection name in the response, and will omit additional info
656
661
* @param {number } [options.batchSize=null] The batchSize for the returned command cursor or if pre 2.8 the systems batch collection
657
662
* @param {(ReadPreference|string) } [options.readPreference=null] The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
658
663
* @param {ClientSession } [options.session] optional session to use for this operation
@@ -678,8 +683,10 @@ Db.prototype.listCollections = function(filter, options) {
678
683
if ( this . serverConfig . capabilities ( ) . hasListCollectionsCommand ) {
679
684
// Cursor options
680
685
var cursor = options . batchSize ? { batchSize : options . batchSize } : { } ;
686
+
687
+ const nameOnly = typeof options . nameOnly === 'boolean' ? options . nameOnly : false ;
681
688
// Build the command
682
- var command = { listCollections : true , filter : filter , cursor : cursor } ;
689
+ var command = { listCollections : true , filter, cursor, nameOnly } ;
683
690
// Set the AggregationCursor constructor
684
691
options . cursorFactory = CommandCursor ;
685
692
// Create the cursor
@@ -917,6 +924,7 @@ Db.prototype.collections = function(options, callback) {
917
924
} ;
918
925
919
926
var collections = function ( self , options , callback ) {
927
+ options = Object . assign ( { } , options , { nameOnly : true } ) ;
920
928
// Let's get the collection names
921
929
self . listCollections ( { } , options ) . toArray ( function ( err , documents ) {
922
930
if ( err != null ) return handleCallback ( callback , err , null ) ;
0 commit comments