Skip to content

Commit 38e1f8f

Browse files
authored
Merge branch 'main' into dependabot/npm_and_yarn/eslint-plugin-mocha-11.1.0
2 parents 1bc3676 + d03a6bd commit 38e1f8f

File tree

19 files changed

+132
-97
lines changed

19 files changed

+132
-97
lines changed

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/collection.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,17 @@ export class Collection<TSchema extends Document = Document> {
172172
/** @internal */
173173
client: MongoClient;
174174

175+
/**
176+
* Get the database object for the collection.
177+
*/
178+
readonly db: Db;
179+
175180
/**
176181
* Create a new Collection instance
177182
* @internal
178183
*/
179184
constructor(db: Db, name: string, options?: CollectionOptions) {
185+
this.db = db;
180186
// Internal state
181187
this.s = {
182188
db,
@@ -228,7 +234,7 @@ export class Collection<TSchema extends Document = Document> {
228234
*/
229235
get readConcern(): ReadConcern | undefined {
230236
if (this.s.readConcern == null) {
231-
return this.s.db.readConcern;
237+
return this.db.readConcern;
232238
}
233239
return this.s.readConcern;
234240
}
@@ -239,7 +245,7 @@ export class Collection<TSchema extends Document = Document> {
239245
*/
240246
get readPreference(): ReadPreference | undefined {
241247
if (this.s.readPreference == null) {
242-
return this.s.db.readPreference;
248+
return this.db.readPreference;
243249
}
244250

245251
return this.s.readPreference;
@@ -255,7 +261,7 @@ export class Collection<TSchema extends Document = Document> {
255261
*/
256262
get writeConcern(): WriteConcern | undefined {
257263
if (this.s.writeConcern == null) {
258-
return this.s.db.writeConcern;
264+
return this.db.writeConcern;
259265
}
260266
return this.s.writeConcern;
261267
}
@@ -509,7 +515,7 @@ export class Collection<TSchema extends Document = Document> {
509515
* @param options - Optional settings for the command
510516
*/
511517
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);
513519
}
514520

515521
/**
@@ -578,7 +584,7 @@ export class Collection<TSchema extends Document = Document> {
578584
*/
579585
async options(options?: OperationOptions): Promise<Document> {
580586
options = resolveOptions(this, options);
581-
const [collection] = await this.s.db
587+
const [collection] = await this.db
582588
.listCollections({ name: this.collectionName }, { ...options, nameOnly: false })
583589
.toArray();
584590

src/db.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,10 @@ export class Db {
126126
/** @internal */
127127
s: DbPrivate;
128128

129-
/** @internal */
129+
/**
130+
* Gets the MongoClient associated with the Db.
131+
* @public
132+
*/
130133
readonly client: MongoClient;
131134

132135
public static SYSTEM_NAMESPACE_COLLECTION = CONSTANTS.SYSTEM_NAMESPACE_COLLECTION;

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/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) {

test/integration/change-streams/change_stream.test.ts

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
} from '../../mongodb';
2525
import * as mock from '../../tools/mongodb-mock/index';
2626
import { TestBuilder, UnifiedTestSuiteBuilder } from '../../tools/unified_suite_builder';
27-
import { type FailPoint, sleep } from '../../tools/utils';
27+
import { type FailCommandFailPoint, sleep } from '../../tools/utils';
2828
import { delay, filterForCommands } from '../shared';
2929

3030
const initIteratorMode = async (cs: ChangeStream) => {
@@ -1097,7 +1097,7 @@ describe('Change Streams', function () {
10971097
failCommands: ['getMore'],
10981098
errorCode: unresumableErrorCode
10991099
}
1100-
} as FailPoint);
1100+
} as FailCommandFailPoint);
11011101

11021102
await collection.insertOne({ city: 'New York City' });
11031103
try {
@@ -1912,7 +1912,7 @@ describe('ChangeStream resumability', function () {
19121912
errorCode: code,
19131913
errmsg: message
19141914
}
1915-
} as FailPoint);
1915+
} as FailCommandFailPoint);
19161916

19171917
await collection.insertOne({ name: 'bailey' });
19181918

@@ -1940,7 +1940,7 @@ describe('ChangeStream resumability', function () {
19401940
errorCode: code,
19411941
errmsg: message
19421942
}
1943-
} as FailPoint);
1943+
} as FailCommandFailPoint);
19441944

19451945
// There's an inherent race condition here because we need to make sure that the `aggregates` that succeed when
19461946
// resuming a change stream don't return the change event. So we defer the insert until a period of time
@@ -1979,7 +1979,7 @@ describe('ChangeStream resumability', function () {
19791979
errorCode: resumableErrorCodes[0].code,
19801980
errmsg: resumableErrorCodes[0].message
19811981
}
1982-
} as FailPoint);
1982+
} as FailCommandFailPoint);
19831983

19841984
expect(changeStream.cursor)
19851985
.to.have.property('changeStreamCursorOptions')
@@ -2009,7 +2009,7 @@ describe('ChangeStream resumability', function () {
20092009
failCommands: ['getMore'],
20102010
errorCode: unresumableErrorCode
20112011
}
2012-
} as FailPoint);
2012+
} as FailCommandFailPoint);
20132013

20142014
await initIteratorMode(changeStream);
20152015

@@ -2032,7 +2032,7 @@ describe('ChangeStream resumability', function () {
20322032
failCommands: ['aggregate'],
20332033
errorCode: resumableErrorCode
20342034
}
2035-
} as FailPoint);
2035+
} as FailCommandFailPoint);
20362036

20372037
changeStream = collection.watch([]);
20382038

@@ -2066,7 +2066,7 @@ describe('ChangeStream resumability', function () {
20662066
errorCode: code,
20672067
errmsg: message
20682068
}
2069-
} as FailPoint);
2069+
} as FailCommandFailPoint);
20702070

20712071
await collection.insertOne({ name: 'bailey' });
20722072

@@ -2094,7 +2094,7 @@ describe('ChangeStream resumability', function () {
20942094
errorCode: code,
20952095
errmsg: message
20962096
}
2097-
} as FailPoint);
2097+
} as FailCommandFailPoint);
20982098

20992099
// There's an inherent race condition here because we need to make sure that the `aggregates` that succeed when
21002100
// resuming a change stream don't return the change event. So we defer the insert until a period of time
@@ -2133,7 +2133,7 @@ describe('ChangeStream resumability', function () {
21332133
errorCode: resumableErrorCodes[0].code,
21342134
errmsg: resumableErrorCodes[0].message
21352135
}
2136-
} as FailPoint);
2136+
} as FailCommandFailPoint);
21372137

21382138
expect(changeStream.cursor)
21392139
.to.have.property('changeStreamCursorOptions')
@@ -2163,7 +2163,7 @@ describe('ChangeStream resumability', function () {
21632163
failCommands: ['getMore'],
21642164
errorCode: unresumableErrorCode
21652165
}
2166-
} as FailPoint);
2166+
} as FailCommandFailPoint);
21672167

21682168
await initIteratorMode(changeStream);
21692169

@@ -2186,7 +2186,7 @@ describe('ChangeStream resumability', function () {
21862186
failCommands: ['aggregate'],
21872187
errorCode: resumableErrorCode
21882188
}
2189-
} as FailPoint);
2189+
} as FailCommandFailPoint);
21902190

21912191
changeStream = collection.watch([]);
21922192

@@ -2220,7 +2220,7 @@ describe('ChangeStream resumability', function () {
22202220
errorCode: code,
22212221
errmsg: message
22222222
}
2223-
} as FailPoint);
2223+
} as FailCommandFailPoint);
22242224

22252225
try {
22262226
// tryNext is not blocking and on sharded clusters we don't have control of when
@@ -2255,7 +2255,7 @@ describe('ChangeStream resumability', function () {
22552255
errorCode: code,
22562256
errmsg: message
22572257
}
2258-
} as FailPoint);
2258+
} as FailCommandFailPoint);
22592259

22602260
try {
22612261
// tryNext is not blocking and on sharded clusters we don't have control of when
@@ -2294,7 +2294,7 @@ describe('ChangeStream resumability', function () {
22942294
errorCode: resumableErrorCodes[0].code,
22952295
errmsg: resumableErrorCodes[0].message
22962296
}
2297-
} as FailPoint);
2297+
} as FailCommandFailPoint);
22982298

22992299
expect(changeStream.cursor)
23002300
.to.have.property('changeStreamCursorOptions')
@@ -2324,7 +2324,7 @@ describe('ChangeStream resumability', function () {
23242324
failCommands: ['getMore'],
23252325
errorCode: unresumableErrorCode
23262326
}
2327-
} as FailPoint);
2327+
} as FailCommandFailPoint);
23282328

23292329
await initIteratorMode(changeStream);
23302330

@@ -2345,7 +2345,7 @@ describe('ChangeStream resumability', function () {
23452345
failCommands: ['aggregate'],
23462346
errorCode: resumableErrorCode
23472347
}
2348-
} as FailPoint);
2348+
} as FailCommandFailPoint);
23492349

23502350
changeStream = collection.watch([]);
23512351

@@ -2382,7 +2382,7 @@ describe('ChangeStream resumability', function () {
23822382
errorCode: code,
23832383
errmsg: message
23842384
}
2385-
} as FailPoint);
2385+
} as FailCommandFailPoint);
23862386

23872387
for await (const change of changeStream) {
23882388
const { fullDocument } = change;
@@ -2417,7 +2417,7 @@ describe('ChangeStream resumability', function () {
24172417
errorCode: resumableErrorCodes[0].code,
24182418
errmsg: resumableErrorCodes[0].message
24192419
}
2420-
} as FailPoint);
2420+
} as FailCommandFailPoint);
24212421

24222422
expect(changeStream.cursor)
24232423
.to.have.property('changeStreamCursorOptions')
@@ -2450,7 +2450,7 @@ describe('ChangeStream resumability', function () {
24502450
failCommands: ['getMore'],
24512451
errorCode: unresumableErrorCode
24522452
}
2453-
} as FailPoint);
2453+
} as FailCommandFailPoint);
24542454

24552455
try {
24562456
// eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -2479,7 +2479,7 @@ describe('ChangeStream resumability', function () {
24792479
failCommands: ['aggregate'],
24802480
errorCode: resumableErrorCode
24812481
}
2482-
} as FailPoint);
2482+
} as FailCommandFailPoint);
24832483

24842484
try {
24852485
// eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -2515,7 +2515,7 @@ describe('ChangeStream resumability', function () {
25152515
errorCode: code,
25162516
errmsg: message
25172517
}
2518-
} as FailPoint);
2518+
} as FailCommandFailPoint);
25192519

25202520
const changes = once(changeStream, 'change');
25212521
await once(changeStream.cursor, 'init');
@@ -2545,7 +2545,7 @@ describe('ChangeStream resumability', function () {
25452545
errorCode: code,
25462546
errmsg: message
25472547
}
2548-
} as FailPoint);
2548+
} as FailCommandFailPoint);
25492549

25502550
const changes = once(changeStream, 'change');
25512551
await once(changeStream.cursor, 'init');
@@ -2585,7 +2585,7 @@ describe('ChangeStream resumability', function () {
25852585
errorCode: resumableErrorCodes[0].code,
25862586
errmsg: resumableErrorCodes[0].message
25872587
}
2588-
} as FailPoint);
2588+
} as FailCommandFailPoint);
25892589

25902590
expect(changeStream.cursor)
25912591
.to.have.property('changeStreamCursorOptions')
@@ -2618,7 +2618,7 @@ describe('ChangeStream resumability', function () {
26182618
failCommands: ['getMore'],
26192619
errorCode: unresumableErrorCode
26202620
}
2621-
} as FailPoint);
2621+
} as FailCommandFailPoint);
26222622

26232623
const willBeError = once(changeStream, 'change').catch(error => error);
26242624
await once(changeStream.cursor, 'init');
@@ -2646,7 +2646,7 @@ describe('ChangeStream resumability', function () {
26462646
errorCode: unresumableErrorCode,
26472647
errmsg: 'operation was interrupted'
26482648
}
2649-
} as FailPoint);
2649+
} as FailCommandFailPoint);
26502650

26512651
const willBeError = once(changeStream, 'change').catch(error => error);
26522652
await once(changeStream.cursor, 'init');
@@ -2671,7 +2671,7 @@ describe('ChangeStream resumability', function () {
26712671
failCommands: ['aggregate'],
26722672
errorCode: resumableErrorCode
26732673
}
2674-
} as FailPoint);
2674+
} as FailCommandFailPoint);
26752675

26762676
const willBeError = once(changeStream, 'change').catch(error => error);
26772677
await collection.insertOne({ name: 'bailey' });

0 commit comments

Comments
 (0)