Skip to content

Commit fee8d3e

Browse files
W-A-Jamesdurran
andauthored
feat(NODE-3568)!: ensure includeResultsMetadata is false by default (#3786)
Co-authored-by: Durran Jordan <[email protected]>
1 parent ee540dd commit fee8d3e

File tree

14 files changed

+344
-435
lines changed

14 files changed

+344
-435
lines changed

Diff for: src/client-side-encryption/client_encryption.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ export class ClientEncryption implements StateMachineExecutable {
444444
this._keyVaultNamespace
445445
);
446446

447-
const { value } = await this._keyVaultClient
447+
const value = await this._keyVaultClient
448448
.db(dbName)
449449
.collection<DataKey>(collectionName)
450450
.findOneAndUpdate(
@@ -506,7 +506,7 @@ export class ClientEncryption implements StateMachineExecutable {
506506
}
507507
}
508508
];
509-
const { value } = await this._keyVaultClient
509+
const value = await this._keyVaultClient
510510
.db(dbName)
511511
.collection<DataKey>(collectionName)
512512
.findOneAndUpdate({ _id }, pipeline, {

Diff for: src/collection.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -819,8 +819,8 @@ export class Collection<TSchema extends Document = Document> {
819819
async findOneAndDelete(
820820
filter: Filter<TSchema>,
821821
options: FindOneAndDeleteOptions
822-
): Promise<ModifyResult<TSchema>>;
823-
async findOneAndDelete(filter: Filter<TSchema>): Promise<ModifyResult<TSchema>>;
822+
): Promise<WithId<TSchema> | null>;
823+
async findOneAndDelete(filter: Filter<TSchema>): Promise<WithId<TSchema> | null>;
824824
async findOneAndDelete(
825825
filter: Filter<TSchema>,
826826
options?: FindOneAndDeleteOptions
@@ -856,11 +856,11 @@ export class Collection<TSchema extends Document = Document> {
856856
filter: Filter<TSchema>,
857857
replacement: WithoutId<TSchema>,
858858
options: FindOneAndReplaceOptions
859-
): Promise<ModifyResult<TSchema>>;
859+
): Promise<WithId<TSchema> | null>;
860860
async findOneAndReplace(
861861
filter: Filter<TSchema>,
862862
replacement: WithoutId<TSchema>
863-
): Promise<ModifyResult<TSchema>>;
863+
): Promise<WithId<TSchema> | null>;
864864
async findOneAndReplace(
865865
filter: Filter<TSchema>,
866866
replacement: WithoutId<TSchema>,
@@ -898,11 +898,11 @@ export class Collection<TSchema extends Document = Document> {
898898
filter: Filter<TSchema>,
899899
update: UpdateFilter<TSchema>,
900900
options: FindOneAndUpdateOptions
901-
): Promise<ModifyResult<TSchema>>;
901+
): Promise<WithId<TSchema> | null>;
902902
async findOneAndUpdate(
903903
filter: Filter<TSchema>,
904904
update: UpdateFilter<TSchema>
905-
): Promise<ModifyResult<TSchema>>;
905+
): Promise<WithId<TSchema> | null>;
906906
async findOneAndUpdate(
907907
filter: Filter<TSchema>,
908908
update: UpdateFilter<TSchema>,

Diff for: src/operations/find_and_modify.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ export interface FindOneAndDeleteOptions extends CommandOperationOptions {
3030
/** Map of parameter names and values that can be accessed using $$var (requires MongoDB 5.0). */
3131
let?: Document;
3232
/**
33-
* Return the ModifyResult instead of the modified document. Defaults to true
34-
* but will default to false in the next major version.
33+
* Return the ModifyResult instead of the modified document. Defaults to false
3534
*/
3635
includeResultMetadata?: boolean;
3736
}
@@ -142,7 +141,7 @@ class FindAndModifyOperation extends CommandOperation<Document> {
142141
upsert: false
143142
};
144143

145-
options.includeResultMetadata ??= true;
144+
options.includeResultMetadata ??= false;
146145

147146
const sort = formatSort(options.sort);
148147
if (sort) {

Diff for: test/integration/crud/crud_api.test.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ describe('CRUD API', function () {
638638
it('returns the modify result', async function () {
639639
const result = await collection.findOneAndDelete(
640640
{ a: 1 },
641-
{ projection: { b: 1 }, sort: { a: 1 } }
641+
{ projection: { b: 1 }, sort: { a: 1 }, includeResultMetadata: true }
642642
);
643643
expect(result?.lastErrorObject.n).to.equal(1);
644644
expect(result?.value.b).to.equal(1);
@@ -685,7 +685,8 @@ describe('CRUD API', function () {
685685
projection: { b: 1, c: 1 },
686686
sort: { a: 1 },
687687
returnDocument: ReturnDocument.AFTER,
688-
upsert: true
688+
upsert: true,
689+
includeResultMetadata: true
689690
}
690691
);
691692
expect(result?.lastErrorObject.n).to.equal(1);
@@ -742,7 +743,8 @@ describe('CRUD API', function () {
742743
projection: { b: 1, d: 1 },
743744
sort: { a: 1 },
744745
returnDocument: ReturnDocument.AFTER,
745-
upsert: true
746+
upsert: true,
747+
includeResultMetadata: true
746748
}
747749
);
748750
expect(result?.lastErrorObject.n).to.equal(1);

Diff for: test/integration/crud/explain.test.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describe('CRUD API explain option', function () {
4242
{
4343
name: 'findOneAndDelete',
4444
op: async (explain: boolean | string) =>
45-
await collection.findOneAndDelete({ a: 1 }, { explain })
45+
await collection.findOneAndDelete({ a: 1 }, { explain, includeResultMetadata: true })
4646
},
4747
{
4848
name: 'findOne',
@@ -52,7 +52,11 @@ describe('CRUD API explain option', function () {
5252
{
5353
name: 'findOneAndReplace',
5454
op: async (explain: boolean | string) =>
55-
await collection.findOneAndReplace({ a: 1 }, { a: 2 }, { explain })
55+
await collection.findOneAndReplace(
56+
{ a: 1 },
57+
{ a: 2 },
58+
{ explain, includeResultMetadata: true }
59+
)
5660
},
5761
{
5862
name: 'aggregate',

0 commit comments

Comments
 (0)