Skip to content

Commit ef44844

Browse files
committed
chore: remove db from collection private
1 parent 48b12c3 commit ef44844

File tree

9 files changed

+23
-25
lines changed

9 files changed

+23
-25
lines changed

src/admin.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ export class Admin {
7575
*/
7676
async command(command: Document, options?: RunCommandOptions): Promise<Document> {
7777
return await executeOperation(
78-
this.s.db.client,
78+
this.db.client,
7979
new RunCommandOperation(new MongoDBNamespace('admin'), command, {
8080
...resolveBSONOptions(options),
8181
session: options?.session,
8282
readPreference: options?.readPreference,
83-
timeoutMS: options?.timeoutMS ?? this.s.db.timeoutMS
83+
timeoutMS: options?.timeoutMS ?? this.db.timeoutMS
8484
})
8585
);
8686
}
@@ -129,8 +129,8 @@ export class Admin {
129129
*/
130130
async removeUser(username: string, options?: RemoveUserOptions): Promise<boolean> {
131131
return await executeOperation(
132-
this.s.db.client,
133-
new RemoveUserOperation(this.s.db, username, { dbName: 'admin', ...options })
132+
this.db.client,
133+
new RemoveUserOperation(this.db, username, { dbName: 'admin', ...options })
134134
);
135135
}
136136

@@ -145,7 +145,7 @@ export class Admin {
145145
options: ValidateCollectionOptions = {}
146146
): Promise<Document> {
147147
return await executeOperation(
148-
this.s.db.client,
148+
this.db.client,
149149
new ValidateCollectionOperation(this, collectionName, options)
150150
);
151151
}
@@ -157,8 +157,8 @@ export class Admin {
157157
*/
158158
async listDatabases(options?: ListDatabasesOptions): Promise<ListDatabasesResult> {
159159
return await executeOperation(
160-
this.s.db.client,
161-
new ListDatabasesOperation(this.s.db, { timeoutMS: this.s.db.timeoutMS, ...options })
160+
this.db.client,
161+
new ListDatabasesOperation(this.db, { timeoutMS: this.db.timeoutMS, ...options })
162162
);
163163
}
164164

src/bulk/common.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ export abstract class BulkOperationBase {
900900

901901
// Final options for retryable writes
902902
let finalOptions = Object.assign({}, options);
903-
finalOptions = applyRetryableWrites(finalOptions, collection.s.db);
903+
finalOptions = applyRetryableWrites(finalOptions, collection.db);
904904

905905
// Final results
906906
const bulkResult: BulkResult = {
@@ -1228,7 +1228,7 @@ export abstract class BulkOperationBase {
12281228
private shouldForceServerObjectId(): boolean {
12291229
return (
12301230
this.s.options.forceServerObjectId === true ||
1231-
this.s.collection.s.db.options?.forceServerObjectId === true
1231+
this.s.collection.db.options?.forceServerObjectId === true
12321232
);
12331233
}
12341234
}

src/change_stream.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ export class ChangeStream<
674674

675675
if (parent instanceof Collection) {
676676
this.type = CHANGE_DOMAIN_TYPES.COLLECTION;
677-
serverSelectionTimeoutMS = parent.s.db.client.options.serverSelectionTimeoutMS;
677+
serverSelectionTimeoutMS = parent.db.client.options.serverSelectionTimeoutMS;
678678
} else if (parent instanceof Db) {
679679
this.type = CHANGE_DOMAIN_TYPES.DATABASE;
680680
serverSelectionTimeoutMS = parent.client.options.serverSelectionTimeoutMS;

src/collection.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ export interface CollectionOptions extends BSONSerializeOptions, WriteConcernOpt
129129
/** @internal */
130130
export interface CollectionPrivate {
131131
pkFactory: PkFactory;
132-
db: Db;
133132
options: any;
134133
namespace: MongoDBCollectionNamespace;
135134
readPreference?: ReadPreference;
@@ -185,7 +184,6 @@ export class Collection<TSchema extends Document = Document> {
185184
this.db = db;
186185
// Internal state
187186
this.s = {
188-
db,
189187
options,
190188
namespace: new MongoDBCollectionNamespace(db.databaseName, name),
191189
pkFactory: db.options?.pkFactory ?? DEFAULT_PK_FACTORY,
@@ -234,7 +232,7 @@ export class Collection<TSchema extends Document = Document> {
234232
*/
235233
get readConcern(): ReadConcern | undefined {
236234
if (this.s.readConcern == null) {
237-
return this.s.db.readConcern;
235+
return this.db.readConcern;
238236
}
239237
return this.s.readConcern;
240238
}
@@ -245,7 +243,7 @@ export class Collection<TSchema extends Document = Document> {
245243
*/
246244
get readPreference(): ReadPreference | undefined {
247245
if (this.s.readPreference == null) {
248-
return this.s.db.readPreference;
246+
return this.db.readPreference;
249247
}
250248

251249
return this.s.readPreference;
@@ -261,7 +259,7 @@ export class Collection<TSchema extends Document = Document> {
261259
*/
262260
get writeConcern(): WriteConcern | undefined {
263261
if (this.s.writeConcern == null) {
264-
return this.s.db.writeConcern;
262+
return this.db.writeConcern;
265263
}
266264
return this.s.writeConcern;
267265
}
@@ -515,7 +513,7 @@ export class Collection<TSchema extends Document = Document> {
515513
* @param options - Optional settings for the command
516514
*/
517515
async drop(options?: DropCollectionOptions): Promise<boolean> {
518-
return await this.s.db.dropCollection(this.collectionName, options);
516+
return await this.db.dropCollection(this.collectionName, options);
519517
}
520518

521519
/**
@@ -584,7 +582,7 @@ export class Collection<TSchema extends Document = Document> {
584582
*/
585583
async options(options?: OperationOptions): Promise<Document> {
586584
options = resolveOptions(this, options);
587-
const [collection] = await this.s.db
585+
const [collection] = await this.db
588586
.listCollections({ name: this.collectionName }, { ...options, nameOnly: false })
589587
.toArray();
590588

src/gridfs/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,13 @@ export class GridFSBucket extends TypedEventEmitter<GridFSBucketEvents> {
160160
* @param id - The id of the file doc
161161
*/
162162
async delete(id: ObjectId, options?: { timeoutMS: number }): Promise<void> {
163-
const { timeoutMS } = resolveOptions(this.s.db, options);
163+
const { timeoutMS } = resolveOptions(this.db, options);
164164
let timeoutContext: CSOTTimeoutContext | undefined = undefined;
165165

166166
if (timeoutMS) {
167167
timeoutContext = new CSOTTimeoutContext({
168168
timeoutMS,
169-
serverSelectionTimeoutMS: this.s.db.client.s.options.serverSelectionTimeoutMS
169+
serverSelectionTimeoutMS: this.db.client.s.options.serverSelectionTimeoutMS
170170
});
171171
}
172172

@@ -240,13 +240,13 @@ export class GridFSBucket extends TypedEventEmitter<GridFSBucketEvents> {
240240

241241
/** Removes this bucket's files collection, followed by its chunks collection. */
242242
async drop(options?: { timeoutMS: number }): Promise<void> {
243-
const { timeoutMS } = resolveOptions(this.s.db, options);
243+
const { timeoutMS } = resolveOptions(this.db, options);
244244
let timeoutContext: CSOTTimeoutContext | undefined = undefined;
245245

246246
if (timeoutMS) {
247247
timeoutContext = new CSOTTimeoutContext({
248248
timeoutMS,
249-
serverSelectionTimeoutMS: this.s.db.client.s.options.serverSelectionTimeoutMS
249+
serverSelectionTimeoutMS: this.db.client.s.options.serverSelectionTimeoutMS
250250
});
251251
}
252252

src/gridfs/upload.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ export class GridFSBucketWriteStream extends Writable {
146146
if (options.timeoutMS != null)
147147
this.timeoutContext = new CSOTTimeoutContext({
148148
timeoutMS: options.timeoutMS,
149-
serverSelectionTimeoutMS: resolveTimeoutOptions(this.bucket.s.db.client, {})
149+
serverSelectionTimeoutMS: resolveTimeoutOptions(this.bucket.db.client, {})
150150
.serverSelectionTimeoutMS
151151
});
152152
}

src/operations/rename.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export class RenameOperation extends CommandOperation<Document> {
4848
}
4949

5050
override handleOk(_response: InstanceType<typeof this.SERVER_COMMAND_RESPONSE_TYPE>): Document {
51-
return new Collection(this.collection.s.db, this.newName, this.collection.s.options);
51+
return new Collection(this.collection.db, this.newName, this.collection.s.options);
5252
}
5353
}
5454

src/operations/validate_collection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class ValidateCollectionOperation extends CommandOperation<Document> {
1919
collectionName: string;
2020

2121
constructor(admin: Admin, collectionName: string, options: ValidateCollectionOptions) {
22-
super(admin.s.db, options);
22+
super(admin.db, options);
2323
this.options = options;
2424
this.collectionName = collectionName;
2525
}

src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1362,7 +1362,7 @@ export function maybeAddIdToDocuments(
13621362
options: { forceServerObjectId?: boolean }
13631363
): Document {
13641364
const forceServerObjectId =
1365-
options.forceServerObjectId ?? collection.s.db.options?.forceServerObjectId ?? false;
1365+
options.forceServerObjectId ?? collection.db.options?.forceServerObjectId ?? false;
13661366

13671367
// no need to modify the docs if server sets the ObjectId
13681368
if (forceServerObjectId) {

0 commit comments

Comments
 (0)