@@ -12,10 +12,12 @@ import {
12
12
} from '../bson' ;
13
13
import { type ProxyOptions } from '../cmap/connection' ;
14
14
import { CursorTimeoutContext } from '../cursor/abstract_cursor' ;
15
+ import { type ListCollectionsCursor } from '../cursor/list_collections_cursor' ;
15
16
import { getSocks , type SocksLib } from '../deps' ;
16
17
import { MongoOperationTimeoutError } from '../error' ;
17
18
import { type MongoClient , type MongoClientOptions } from '../mongo_client' ;
18
19
import { type Abortable } from '../mongo_types' ;
20
+ import { type CollectionInfo } from '../operations/list_collections' ;
19
21
import { Timeout , type TimeoutContext , TimeoutError } from '../timeout' ;
20
22
import {
21
23
addAbortListener ,
@@ -218,14 +220,15 @@ export class StateMachine {
218
220
) ;
219
221
}
220
222
221
- const collInfo = await this . fetchCollectionInfo (
223
+ const collInfoCursor = this . fetchCollectionInfo (
222
224
metaDataClient ,
223
225
context . ns ,
224
226
filter ,
225
227
options
226
228
) ;
227
- if ( collInfo ) {
228
- context . addMongoOperationResponse ( collInfo ) ;
229
+
230
+ for await ( const collInfo of collInfoCursor ) {
231
+ context . addMongoOperationResponse ( serialize ( collInfo ) ) ;
229
232
}
230
233
231
234
context . finishMongoOperation ( ) ;
@@ -527,29 +530,24 @@ export class StateMachine {
527
530
* @param filter - A filter for the listCollections command
528
531
* @param callback - Invoked with the info of the requested collection, or with an error
529
532
*/
530
- async fetchCollectionInfo (
533
+ fetchCollectionInfo (
531
534
client : MongoClient ,
532
535
ns : string ,
533
536
filter : Document ,
534
537
options ?: { timeoutContext ?: TimeoutContext } & Abortable
535
- ) : Promise < Uint8Array | null > {
538
+ ) : ListCollectionsCursor < CollectionInfo > {
536
539
const { db } = MongoDBCollectionNamespace . fromString ( ns ) ;
537
540
538
541
const cursor = client . db ( db ) . listCollections ( filter , {
539
542
promoteLongs : false ,
540
543
promoteValues : false ,
541
544
timeoutContext :
542
545
options ?. timeoutContext && new CursorTimeoutContext ( options ?. timeoutContext , Symbol ( ) ) ,
543
- signal : options ?. signal
546
+ signal : options ?. signal ,
547
+ nameOnly : false
544
548
} ) ;
545
549
546
- // There is always exactly zero or one matching documents, so this should always exhaust the cursor
547
- // in a single batch. We call `toArray()` just to be safe and ensure that the cursor is always
548
- // exhausted and closed.
549
- const collections = await cursor . toArray ( ) ;
550
-
551
- const info = collections . length > 0 ? serialize ( collections [ 0 ] ) : null ;
552
- return info ;
550
+ return cursor ;
553
551
}
554
552
555
553
/**
0 commit comments