From e461f1702e2cfb8c4f29f563ef3d68e754f879f0 Mon Sep 17 00:00:00 2001 From: Durran Jordan Date: Thu, 28 Aug 2025 22:20:38 +0200 Subject: [PATCH 1/5] feat(NODE-7125): expose db and client --- src/collection.ts | 7 +++++++ src/db.ts | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/collection.ts b/src/collection.ts index 37339881c3b..5c0ba429092 100644 --- a/src/collection.ts +++ b/src/collection.ts @@ -192,6 +192,13 @@ export class Collection { this.client = db.client; } + /** + * Get the database object for the collection. + */ + get db(): Db { + return this.s.db; + } + /** * The name of the database this collection belongs to */ diff --git a/src/db.ts b/src/db.ts index a5c678f4f1e..f8d9d8c55e6 100644 --- a/src/db.ts +++ b/src/db.ts @@ -126,7 +126,7 @@ export class Db { /** @internal */ s: DbPrivate; - /** @internal */ + /** @public */ readonly client: MongoClient; public static SYSTEM_NAMESPACE_COLLECTION = CONSTANTS.SYSTEM_NAMESPACE_COLLECTION; From 48b12c37e536ff093a83b5952a860967174e5f47 Mon Sep 17 00:00:00 2001 From: Durran Jordan Date: Fri, 29 Aug 2025 17:45:08 +0200 Subject: [PATCH 2/5] chore: comments --- src/collection.ts | 13 ++++++------- src/db.ts | 5 ++++- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/collection.ts b/src/collection.ts index 5c0ba429092..3c1eb8296ec 100644 --- a/src/collection.ts +++ b/src/collection.ts @@ -172,11 +172,17 @@ export class Collection { /** @internal */ client: MongoClient; + /** + * Get the database object for the collection. + */ + readonly db: Db; + /** * Create a new Collection instance * @internal */ constructor(db: Db, name: string, options?: CollectionOptions) { + this.db = db; // Internal state this.s = { db, @@ -192,13 +198,6 @@ export class Collection { this.client = db.client; } - /** - * Get the database object for the collection. - */ - get db(): Db { - return this.s.db; - } - /** * The name of the database this collection belongs to */ diff --git a/src/db.ts b/src/db.ts index f8d9d8c55e6..54724ae31be 100644 --- a/src/db.ts +++ b/src/db.ts @@ -126,7 +126,10 @@ export class Db { /** @internal */ s: DbPrivate; - /** @public */ + /** + * Gets the MongoClient associated with the Db. + * @public + */ readonly client: MongoClient; public static SYSTEM_NAMESPACE_COLLECTION = CONSTANTS.SYSTEM_NAMESPACE_COLLECTION; From ef44844cd87488e7bda14b008a0cc774df9eddfa Mon Sep 17 00:00:00 2001 From: Durran Jordan Date: Fri, 29 Aug 2025 17:56:41 +0200 Subject: [PATCH 3/5] chore: remove db from collection private --- src/admin.ts | 14 +++++++------- src/bulk/common.ts | 4 ++-- src/change_stream.ts | 2 +- src/collection.ts | 12 +++++------- src/gridfs/index.ts | 8 ++++---- src/gridfs/upload.ts | 2 +- src/operations/rename.ts | 2 +- src/operations/validate_collection.ts | 2 +- src/utils.ts | 2 +- 9 files changed, 23 insertions(+), 25 deletions(-) diff --git a/src/admin.ts b/src/admin.ts index c75a51fa9dd..f799d45924d 100644 --- a/src/admin.ts +++ b/src/admin.ts @@ -75,12 +75,12 @@ export class Admin { */ async command(command: Document, options?: RunCommandOptions): Promise { return await executeOperation( - this.s.db.client, + this.db.client, new RunCommandOperation(new MongoDBNamespace('admin'), command, { ...resolveBSONOptions(options), session: options?.session, readPreference: options?.readPreference, - timeoutMS: options?.timeoutMS ?? this.s.db.timeoutMS + timeoutMS: options?.timeoutMS ?? this.db.timeoutMS }) ); } @@ -129,8 +129,8 @@ export class Admin { */ async removeUser(username: string, options?: RemoveUserOptions): Promise { return await executeOperation( - this.s.db.client, - new RemoveUserOperation(this.s.db, username, { dbName: 'admin', ...options }) + this.db.client, + new RemoveUserOperation(this.db, username, { dbName: 'admin', ...options }) ); } @@ -145,7 +145,7 @@ export class Admin { options: ValidateCollectionOptions = {} ): Promise { return await executeOperation( - this.s.db.client, + this.db.client, new ValidateCollectionOperation(this, collectionName, options) ); } @@ -157,8 +157,8 @@ export class Admin { */ async listDatabases(options?: ListDatabasesOptions): Promise { return await executeOperation( - this.s.db.client, - new ListDatabasesOperation(this.s.db, { timeoutMS: this.s.db.timeoutMS, ...options }) + this.db.client, + new ListDatabasesOperation(this.db, { timeoutMS: this.db.timeoutMS, ...options }) ); } diff --git a/src/bulk/common.ts b/src/bulk/common.ts index 4b1578903ea..211c802c182 100644 --- a/src/bulk/common.ts +++ b/src/bulk/common.ts @@ -900,7 +900,7 @@ export abstract class BulkOperationBase { // Final options for retryable writes let finalOptions = Object.assign({}, options); - finalOptions = applyRetryableWrites(finalOptions, collection.s.db); + finalOptions = applyRetryableWrites(finalOptions, collection.db); // Final results const bulkResult: BulkResult = { @@ -1228,7 +1228,7 @@ export abstract class BulkOperationBase { private shouldForceServerObjectId(): boolean { return ( this.s.options.forceServerObjectId === true || - this.s.collection.s.db.options?.forceServerObjectId === true + this.s.collection.db.options?.forceServerObjectId === true ); } } diff --git a/src/change_stream.ts b/src/change_stream.ts index ed847519e8a..fa62e7065b4 100644 --- a/src/change_stream.ts +++ b/src/change_stream.ts @@ -674,7 +674,7 @@ export class ChangeStream< if (parent instanceof Collection) { this.type = CHANGE_DOMAIN_TYPES.COLLECTION; - serverSelectionTimeoutMS = parent.s.db.client.options.serverSelectionTimeoutMS; + serverSelectionTimeoutMS = parent.db.client.options.serverSelectionTimeoutMS; } else if (parent instanceof Db) { this.type = CHANGE_DOMAIN_TYPES.DATABASE; serverSelectionTimeoutMS = parent.client.options.serverSelectionTimeoutMS; diff --git a/src/collection.ts b/src/collection.ts index 3c1eb8296ec..05e7d9befb8 100644 --- a/src/collection.ts +++ b/src/collection.ts @@ -129,7 +129,6 @@ export interface CollectionOptions extends BSONSerializeOptions, WriteConcernOpt /** @internal */ export interface CollectionPrivate { pkFactory: PkFactory; - db: Db; options: any; namespace: MongoDBCollectionNamespace; readPreference?: ReadPreference; @@ -185,7 +184,6 @@ export class Collection { this.db = db; // Internal state this.s = { - db, options, namespace: new MongoDBCollectionNamespace(db.databaseName, name), pkFactory: db.options?.pkFactory ?? DEFAULT_PK_FACTORY, @@ -234,7 +232,7 @@ export class Collection { */ get readConcern(): ReadConcern | undefined { if (this.s.readConcern == null) { - return this.s.db.readConcern; + return this.db.readConcern; } return this.s.readConcern; } @@ -245,7 +243,7 @@ export class Collection { */ get readPreference(): ReadPreference | undefined { if (this.s.readPreference == null) { - return this.s.db.readPreference; + return this.db.readPreference; } return this.s.readPreference; @@ -261,7 +259,7 @@ export class Collection { */ get writeConcern(): WriteConcern | undefined { if (this.s.writeConcern == null) { - return this.s.db.writeConcern; + return this.db.writeConcern; } return this.s.writeConcern; } @@ -515,7 +513,7 @@ export class Collection { * @param options - Optional settings for the command */ async drop(options?: DropCollectionOptions): Promise { - return await this.s.db.dropCollection(this.collectionName, options); + return await this.db.dropCollection(this.collectionName, options); } /** @@ -584,7 +582,7 @@ export class Collection { */ async options(options?: OperationOptions): Promise { options = resolveOptions(this, options); - const [collection] = await this.s.db + const [collection] = await this.db .listCollections({ name: this.collectionName }, { ...options, nameOnly: false }) .toArray(); diff --git a/src/gridfs/index.ts b/src/gridfs/index.ts index f62267b0a99..222b92c9297 100644 --- a/src/gridfs/index.ts +++ b/src/gridfs/index.ts @@ -160,13 +160,13 @@ export class GridFSBucket extends TypedEventEmitter { * @param id - The id of the file doc */ async delete(id: ObjectId, options?: { timeoutMS: number }): Promise { - const { timeoutMS } = resolveOptions(this.s.db, options); + const { timeoutMS } = resolveOptions(this.db, options); let timeoutContext: CSOTTimeoutContext | undefined = undefined; if (timeoutMS) { timeoutContext = new CSOTTimeoutContext({ timeoutMS, - serverSelectionTimeoutMS: this.s.db.client.s.options.serverSelectionTimeoutMS + serverSelectionTimeoutMS: this.db.client.s.options.serverSelectionTimeoutMS }); } @@ -240,13 +240,13 @@ export class GridFSBucket extends TypedEventEmitter { /** Removes this bucket's files collection, followed by its chunks collection. */ async drop(options?: { timeoutMS: number }): Promise { - const { timeoutMS } = resolveOptions(this.s.db, options); + const { timeoutMS } = resolveOptions(this.db, options); let timeoutContext: CSOTTimeoutContext | undefined = undefined; if (timeoutMS) { timeoutContext = new CSOTTimeoutContext({ timeoutMS, - serverSelectionTimeoutMS: this.s.db.client.s.options.serverSelectionTimeoutMS + serverSelectionTimeoutMS: this.db.client.s.options.serverSelectionTimeoutMS }); } diff --git a/src/gridfs/upload.ts b/src/gridfs/upload.ts index 02317264c7c..cf1edb3a6eb 100644 --- a/src/gridfs/upload.ts +++ b/src/gridfs/upload.ts @@ -146,7 +146,7 @@ export class GridFSBucketWriteStream extends Writable { if (options.timeoutMS != null) this.timeoutContext = new CSOTTimeoutContext({ timeoutMS: options.timeoutMS, - serverSelectionTimeoutMS: resolveTimeoutOptions(this.bucket.s.db.client, {}) + serverSelectionTimeoutMS: resolveTimeoutOptions(this.bucket.db.client, {}) .serverSelectionTimeoutMS }); } diff --git a/src/operations/rename.ts b/src/operations/rename.ts index 0ba34c2baf5..a0efb47a6d7 100644 --- a/src/operations/rename.ts +++ b/src/operations/rename.ts @@ -48,7 +48,7 @@ export class RenameOperation extends CommandOperation { } override handleOk(_response: InstanceType): Document { - return new Collection(this.collection.s.db, this.newName, this.collection.s.options); + return new Collection(this.collection.db, this.newName, this.collection.s.options); } } diff --git a/src/operations/validate_collection.ts b/src/operations/validate_collection.ts index 06977178e4e..fcb9fa19b70 100644 --- a/src/operations/validate_collection.ts +++ b/src/operations/validate_collection.ts @@ -19,7 +19,7 @@ export class ValidateCollectionOperation extends CommandOperation { collectionName: string; constructor(admin: Admin, collectionName: string, options: ValidateCollectionOptions) { - super(admin.s.db, options); + super(admin.db, options); this.options = options; this.collectionName = collectionName; } diff --git a/src/utils.ts b/src/utils.ts index c4a68dcd524..c6f40fb43e9 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1362,7 +1362,7 @@ export function maybeAddIdToDocuments( options: { forceServerObjectId?: boolean } ): Document { const forceServerObjectId = - options.forceServerObjectId ?? collection.s.db.options?.forceServerObjectId ?? false; + options.forceServerObjectId ?? collection.db.options?.forceServerObjectId ?? false; // no need to modify the docs if server sets the ObjectId if (forceServerObjectId) { From ccc4155428fbe2435e5e1e037b9219fdec63c61c Mon Sep 17 00:00:00 2001 From: Durran Jordan Date: Fri, 29 Aug 2025 17:58:18 +0200 Subject: [PATCH 4/5] Revert "chore: remove db from collection private" This reverts commit ef44844cd87488e7bda14b008a0cc774df9eddfa. --- src/admin.ts | 14 +++++++------- src/bulk/common.ts | 4 ++-- src/change_stream.ts | 2 +- src/collection.ts | 12 +++++++----- src/gridfs/index.ts | 8 ++++---- src/gridfs/upload.ts | 2 +- src/operations/rename.ts | 2 +- src/operations/validate_collection.ts | 2 +- src/utils.ts | 2 +- 9 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src/admin.ts b/src/admin.ts index f799d45924d..c75a51fa9dd 100644 --- a/src/admin.ts +++ b/src/admin.ts @@ -75,12 +75,12 @@ export class Admin { */ async command(command: Document, options?: RunCommandOptions): Promise { return await executeOperation( - this.db.client, + this.s.db.client, new RunCommandOperation(new MongoDBNamespace('admin'), command, { ...resolveBSONOptions(options), session: options?.session, readPreference: options?.readPreference, - timeoutMS: options?.timeoutMS ?? this.db.timeoutMS + timeoutMS: options?.timeoutMS ?? this.s.db.timeoutMS }) ); } @@ -129,8 +129,8 @@ export class Admin { */ async removeUser(username: string, options?: RemoveUserOptions): Promise { return await executeOperation( - this.db.client, - new RemoveUserOperation(this.db, username, { dbName: 'admin', ...options }) + this.s.db.client, + new RemoveUserOperation(this.s.db, username, { dbName: 'admin', ...options }) ); } @@ -145,7 +145,7 @@ export class Admin { options: ValidateCollectionOptions = {} ): Promise { return await executeOperation( - this.db.client, + this.s.db.client, new ValidateCollectionOperation(this, collectionName, options) ); } @@ -157,8 +157,8 @@ export class Admin { */ async listDatabases(options?: ListDatabasesOptions): Promise { return await executeOperation( - this.db.client, - new ListDatabasesOperation(this.db, { timeoutMS: this.db.timeoutMS, ...options }) + this.s.db.client, + new ListDatabasesOperation(this.s.db, { timeoutMS: this.s.db.timeoutMS, ...options }) ); } diff --git a/src/bulk/common.ts b/src/bulk/common.ts index 211c802c182..4b1578903ea 100644 --- a/src/bulk/common.ts +++ b/src/bulk/common.ts @@ -900,7 +900,7 @@ export abstract class BulkOperationBase { // Final options for retryable writes let finalOptions = Object.assign({}, options); - finalOptions = applyRetryableWrites(finalOptions, collection.db); + finalOptions = applyRetryableWrites(finalOptions, collection.s.db); // Final results const bulkResult: BulkResult = { @@ -1228,7 +1228,7 @@ export abstract class BulkOperationBase { private shouldForceServerObjectId(): boolean { return ( this.s.options.forceServerObjectId === true || - this.s.collection.db.options?.forceServerObjectId === true + this.s.collection.s.db.options?.forceServerObjectId === true ); } } diff --git a/src/change_stream.ts b/src/change_stream.ts index fa62e7065b4..ed847519e8a 100644 --- a/src/change_stream.ts +++ b/src/change_stream.ts @@ -674,7 +674,7 @@ export class ChangeStream< if (parent instanceof Collection) { this.type = CHANGE_DOMAIN_TYPES.COLLECTION; - serverSelectionTimeoutMS = parent.db.client.options.serverSelectionTimeoutMS; + serverSelectionTimeoutMS = parent.s.db.client.options.serverSelectionTimeoutMS; } else if (parent instanceof Db) { this.type = CHANGE_DOMAIN_TYPES.DATABASE; serverSelectionTimeoutMS = parent.client.options.serverSelectionTimeoutMS; diff --git a/src/collection.ts b/src/collection.ts index 05e7d9befb8..3c1eb8296ec 100644 --- a/src/collection.ts +++ b/src/collection.ts @@ -129,6 +129,7 @@ export interface CollectionOptions extends BSONSerializeOptions, WriteConcernOpt /** @internal */ export interface CollectionPrivate { pkFactory: PkFactory; + db: Db; options: any; namespace: MongoDBCollectionNamespace; readPreference?: ReadPreference; @@ -184,6 +185,7 @@ export class Collection { this.db = db; // Internal state this.s = { + db, options, namespace: new MongoDBCollectionNamespace(db.databaseName, name), pkFactory: db.options?.pkFactory ?? DEFAULT_PK_FACTORY, @@ -232,7 +234,7 @@ export class Collection { */ get readConcern(): ReadConcern | undefined { if (this.s.readConcern == null) { - return this.db.readConcern; + return this.s.db.readConcern; } return this.s.readConcern; } @@ -243,7 +245,7 @@ export class Collection { */ get readPreference(): ReadPreference | undefined { if (this.s.readPreference == null) { - return this.db.readPreference; + return this.s.db.readPreference; } return this.s.readPreference; @@ -259,7 +261,7 @@ export class Collection { */ get writeConcern(): WriteConcern | undefined { if (this.s.writeConcern == null) { - return this.db.writeConcern; + return this.s.db.writeConcern; } return this.s.writeConcern; } @@ -513,7 +515,7 @@ export class Collection { * @param options - Optional settings for the command */ async drop(options?: DropCollectionOptions): Promise { - return await this.db.dropCollection(this.collectionName, options); + return await this.s.db.dropCollection(this.collectionName, options); } /** @@ -582,7 +584,7 @@ export class Collection { */ async options(options?: OperationOptions): Promise { options = resolveOptions(this, options); - const [collection] = await this.db + const [collection] = await this.s.db .listCollections({ name: this.collectionName }, { ...options, nameOnly: false }) .toArray(); diff --git a/src/gridfs/index.ts b/src/gridfs/index.ts index 222b92c9297..f62267b0a99 100644 --- a/src/gridfs/index.ts +++ b/src/gridfs/index.ts @@ -160,13 +160,13 @@ export class GridFSBucket extends TypedEventEmitter { * @param id - The id of the file doc */ async delete(id: ObjectId, options?: { timeoutMS: number }): Promise { - const { timeoutMS } = resolveOptions(this.db, options); + const { timeoutMS } = resolveOptions(this.s.db, options); let timeoutContext: CSOTTimeoutContext | undefined = undefined; if (timeoutMS) { timeoutContext = new CSOTTimeoutContext({ timeoutMS, - serverSelectionTimeoutMS: this.db.client.s.options.serverSelectionTimeoutMS + serverSelectionTimeoutMS: this.s.db.client.s.options.serverSelectionTimeoutMS }); } @@ -240,13 +240,13 @@ export class GridFSBucket extends TypedEventEmitter { /** Removes this bucket's files collection, followed by its chunks collection. */ async drop(options?: { timeoutMS: number }): Promise { - const { timeoutMS } = resolveOptions(this.db, options); + const { timeoutMS } = resolveOptions(this.s.db, options); let timeoutContext: CSOTTimeoutContext | undefined = undefined; if (timeoutMS) { timeoutContext = new CSOTTimeoutContext({ timeoutMS, - serverSelectionTimeoutMS: this.db.client.s.options.serverSelectionTimeoutMS + serverSelectionTimeoutMS: this.s.db.client.s.options.serverSelectionTimeoutMS }); } diff --git a/src/gridfs/upload.ts b/src/gridfs/upload.ts index cf1edb3a6eb..02317264c7c 100644 --- a/src/gridfs/upload.ts +++ b/src/gridfs/upload.ts @@ -146,7 +146,7 @@ export class GridFSBucketWriteStream extends Writable { if (options.timeoutMS != null) this.timeoutContext = new CSOTTimeoutContext({ timeoutMS: options.timeoutMS, - serverSelectionTimeoutMS: resolveTimeoutOptions(this.bucket.db.client, {}) + serverSelectionTimeoutMS: resolveTimeoutOptions(this.bucket.s.db.client, {}) .serverSelectionTimeoutMS }); } diff --git a/src/operations/rename.ts b/src/operations/rename.ts index a0efb47a6d7..0ba34c2baf5 100644 --- a/src/operations/rename.ts +++ b/src/operations/rename.ts @@ -48,7 +48,7 @@ export class RenameOperation extends CommandOperation { } override handleOk(_response: InstanceType): Document { - return new Collection(this.collection.db, this.newName, this.collection.s.options); + return new Collection(this.collection.s.db, this.newName, this.collection.s.options); } } diff --git a/src/operations/validate_collection.ts b/src/operations/validate_collection.ts index fcb9fa19b70..06977178e4e 100644 --- a/src/operations/validate_collection.ts +++ b/src/operations/validate_collection.ts @@ -19,7 +19,7 @@ export class ValidateCollectionOperation extends CommandOperation { collectionName: string; constructor(admin: Admin, collectionName: string, options: ValidateCollectionOptions) { - super(admin.db, options); + super(admin.s.db, options); this.options = options; this.collectionName = collectionName; } diff --git a/src/utils.ts b/src/utils.ts index c6f40fb43e9..c4a68dcd524 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1362,7 +1362,7 @@ export function maybeAddIdToDocuments( options: { forceServerObjectId?: boolean } ): Document { const forceServerObjectId = - options.forceServerObjectId ?? collection.db.options?.forceServerObjectId ?? false; + options.forceServerObjectId ?? collection.s.db.options?.forceServerObjectId ?? false; // no need to modify the docs if server sets the ObjectId if (forceServerObjectId) { From 3304196d18615c7b5b10bef72c581cf4cb30beba Mon Sep 17 00:00:00 2001 From: Durran Jordan Date: Fri, 29 Aug 2025 18:01:24 +0200 Subject: [PATCH 5/5] chore: remove db from collection private --- src/bulk/common.ts | 4 ++-- src/collection.ts | 10 +++++----- src/operations/rename.ts | 2 +- src/utils.ts | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/bulk/common.ts b/src/bulk/common.ts index 4b1578903ea..211c802c182 100644 --- a/src/bulk/common.ts +++ b/src/bulk/common.ts @@ -900,7 +900,7 @@ export abstract class BulkOperationBase { // Final options for retryable writes let finalOptions = Object.assign({}, options); - finalOptions = applyRetryableWrites(finalOptions, collection.s.db); + finalOptions = applyRetryableWrites(finalOptions, collection.db); // Final results const bulkResult: BulkResult = { @@ -1228,7 +1228,7 @@ export abstract class BulkOperationBase { private shouldForceServerObjectId(): boolean { return ( this.s.options.forceServerObjectId === true || - this.s.collection.s.db.options?.forceServerObjectId === true + this.s.collection.db.options?.forceServerObjectId === true ); } } diff --git a/src/collection.ts b/src/collection.ts index 3c1eb8296ec..f693bdf5a47 100644 --- a/src/collection.ts +++ b/src/collection.ts @@ -234,7 +234,7 @@ export class Collection { */ get readConcern(): ReadConcern | undefined { if (this.s.readConcern == null) { - return this.s.db.readConcern; + return this.db.readConcern; } return this.s.readConcern; } @@ -245,7 +245,7 @@ export class Collection { */ get readPreference(): ReadPreference | undefined { if (this.s.readPreference == null) { - return this.s.db.readPreference; + return this.db.readPreference; } return this.s.readPreference; @@ -261,7 +261,7 @@ export class Collection { */ get writeConcern(): WriteConcern | undefined { if (this.s.writeConcern == null) { - return this.s.db.writeConcern; + return this.db.writeConcern; } return this.s.writeConcern; } @@ -515,7 +515,7 @@ export class Collection { * @param options - Optional settings for the command */ async drop(options?: DropCollectionOptions): Promise { - return await this.s.db.dropCollection(this.collectionName, options); + return await this.db.dropCollection(this.collectionName, options); } /** @@ -584,7 +584,7 @@ export class Collection { */ async options(options?: OperationOptions): Promise { options = resolveOptions(this, options); - const [collection] = await this.s.db + const [collection] = await this.db .listCollections({ name: this.collectionName }, { ...options, nameOnly: false }) .toArray(); diff --git a/src/operations/rename.ts b/src/operations/rename.ts index 0ba34c2baf5..a0efb47a6d7 100644 --- a/src/operations/rename.ts +++ b/src/operations/rename.ts @@ -48,7 +48,7 @@ export class RenameOperation extends CommandOperation { } override handleOk(_response: InstanceType): Document { - return new Collection(this.collection.s.db, this.newName, this.collection.s.options); + return new Collection(this.collection.db, this.newName, this.collection.s.options); } } diff --git a/src/utils.ts b/src/utils.ts index c4a68dcd524..c6f40fb43e9 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1362,7 +1362,7 @@ export function maybeAddIdToDocuments( options: { forceServerObjectId?: boolean } ): Document { const forceServerObjectId = - options.forceServerObjectId ?? collection.s.db.options?.forceServerObjectId ?? false; + options.forceServerObjectId ?? collection.db.options?.forceServerObjectId ?? false; // no need to modify the docs if server sets the ObjectId if (forceServerObjectId) {