@@ -172,11 +172,17 @@ export class Collection<TSchema extends Document = Document> {
172
172
/** @internal */
173
173
client : MongoClient ;
174
174
175
+ /**
176
+ * Get the database object for the collection.
177
+ */
178
+ readonly db : Db ;
179
+
175
180
/**
176
181
* Create a new Collection instance
177
182
* @internal
178
183
*/
179
184
constructor ( db : Db , name : string , options ?: CollectionOptions ) {
185
+ this . db = db ;
180
186
// Internal state
181
187
this . s = {
182
188
db,
@@ -228,7 +234,7 @@ export class Collection<TSchema extends Document = Document> {
228
234
*/
229
235
get readConcern ( ) : ReadConcern | undefined {
230
236
if ( this . s . readConcern == null ) {
231
- return this . s . db . readConcern ;
237
+ return this . db . readConcern ;
232
238
}
233
239
return this . s . readConcern ;
234
240
}
@@ -239,7 +245,7 @@ export class Collection<TSchema extends Document = Document> {
239
245
*/
240
246
get readPreference ( ) : ReadPreference | undefined {
241
247
if ( this . s . readPreference == null ) {
242
- return this . s . db . readPreference ;
248
+ return this . db . readPreference ;
243
249
}
244
250
245
251
return this . s . readPreference ;
@@ -255,7 +261,7 @@ export class Collection<TSchema extends Document = Document> {
255
261
*/
256
262
get writeConcern ( ) : WriteConcern | undefined {
257
263
if ( this . s . writeConcern == null ) {
258
- return this . s . db . writeConcern ;
264
+ return this . db . writeConcern ;
259
265
}
260
266
return this . s . writeConcern ;
261
267
}
@@ -509,7 +515,7 @@ export class Collection<TSchema extends Document = Document> {
509
515
* @param options - Optional settings for the command
510
516
*/
511
517
async drop ( options ?: DropCollectionOptions ) : Promise < boolean > {
512
- return await this . s . db . dropCollection ( this . collectionName , options ) ;
518
+ return await this . db . dropCollection ( this . collectionName , options ) ;
513
519
}
514
520
515
521
/**
@@ -578,7 +584,7 @@ export class Collection<TSchema extends Document = Document> {
578
584
*/
579
585
async options ( options ?: OperationOptions ) : Promise < Document > {
580
586
options = resolveOptions ( this , options ) ;
581
- const [ collection ] = await this . s . db
587
+ const [ collection ] = await this . db
582
588
. listCollections ( { name : this . collectionName } , { ...options , nameOnly : false } )
583
589
. toArray ( ) ;
584
590
0 commit comments