@@ -455,8 +455,10 @@ Db.prototype.collection = function(name, options, callback) {
455455 return callback ( new MongoError ( 'topology was destroyed' ) ) ;
456456 }
457457
458+ const listCollectionOptions = Object . assign ( { } , options , { nameOnly : true } ) ;
459+
458460 // Strict mode
459- this . listCollections ( { name : name } , options ) . toArray ( function ( err , collections ) {
461+ this . listCollections ( { name : name } , listCollectionOptions ) . toArray ( function ( err , collections ) {
460462 if ( err != null ) return handleCallback ( callback , err , null ) ;
461463 if ( collections . length === 0 )
462464 return handleCallback (
@@ -486,9 +488,11 @@ var createCollection = function(self, name, options, callback) {
486488 return callback ( new MongoError ( 'topology was destroyed' ) ) ;
487489 }
488490
491+ const listCollectionOptions = Object . assign ( { } , finalOptions , { nameOnly : true } ) ;
492+
489493 // Check if we have the name
490494 self
491- . listCollections ( { name : name } , finalOptions )
495+ . listCollections ( { name : name } , listCollectionOptions )
492496 . setReadPreference ( ReadPreference . PRIMARY )
493497 . toArray ( function ( err , collections ) {
494498 if ( err != null ) return handleCallback ( callback , err , null ) ;
@@ -653,6 +657,7 @@ var listCollectionsTranforms = function(databaseName) {
653657 * @method
654658 * @param {object } [filter={}] Query to filter collections by
655659 * @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
656661 * @param {number } [options.batchSize=null] The batchSize for the returned command cursor or if pre 2.8 the systems batch collection
657662 * @param {(ReadPreference|string) } [options.readPreference=null] The preferred read preference (ReadPreference.PRIMARY, ReadPreference.PRIMARY_PREFERRED, ReadPreference.SECONDARY, ReadPreference.SECONDARY_PREFERRED, ReadPreference.NEAREST).
658663 * @param {ClientSession } [options.session] optional session to use for this operation
@@ -678,8 +683,10 @@ Db.prototype.listCollections = function(filter, options) {
678683 if ( this . serverConfig . capabilities ( ) . hasListCollectionsCommand ) {
679684 // Cursor options
680685 var cursor = options . batchSize ? { batchSize : options . batchSize } : { } ;
686+
687+ const nameOnly = typeof options . nameOnly === 'boolean' ? options . nameOnly : false ;
681688 // Build the command
682- var command = { listCollections : true , filter : filter , cursor : cursor } ;
689+ var command = { listCollections : true , filter, cursor, nameOnly } ;
683690 // Set the AggregationCursor constructor
684691 options . cursorFactory = CommandCursor ;
685692 // Create the cursor
@@ -917,6 +924,7 @@ Db.prototype.collections = function(options, callback) {
917924} ;
918925
919926var collections = function ( self , options , callback ) {
927+ options = Object . assign ( { } , options , { nameOnly : true } ) ;
920928 // Let's get the collection names
921929 self . listCollections ( { } , options ) . toArray ( function ( err , documents ) {
922930 if ( err != null ) return handleCallback ( callback , err , null ) ;
0 commit comments