Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(NODE-3568)!: ensure includeResultsMetadata is false by default #3786

Merged
merged 21 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/client-side-encryption/client_encryption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ export class ClientEncryption implements StateMachineExecutable {
this._keyVaultNamespace
);

const { value } = await this._keyVaultClient
const value = await this._keyVaultClient
.db(dbName)
.collection<DataKey>(collectionName)
.findOneAndUpdate(
Expand Down Expand Up @@ -506,7 +506,7 @@ export class ClientEncryption implements StateMachineExecutable {
}
}
];
const { value } = await this._keyVaultClient
const value = await this._keyVaultClient
.db(dbName)
.collection<DataKey>(collectionName)
.findOneAndUpdate({ _id }, pipeline, {
Expand Down
12 changes: 6 additions & 6 deletions src/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -819,8 +819,8 @@ export class Collection<TSchema extends Document = Document> {
async findOneAndDelete(
filter: Filter<TSchema>,
options: FindOneAndDeleteOptions
): Promise<ModifyResult<TSchema>>;
async findOneAndDelete(filter: Filter<TSchema>): Promise<ModifyResult<TSchema>>;
): Promise<WithId<TSchema> | null>;
async findOneAndDelete(filter: Filter<TSchema>): Promise<WithId<TSchema> | null>;
async findOneAndDelete(
filter: Filter<TSchema>,
options?: FindOneAndDeleteOptions
Expand Down Expand Up @@ -856,11 +856,11 @@ export class Collection<TSchema extends Document = Document> {
filter: Filter<TSchema>,
replacement: WithoutId<TSchema>,
options: FindOneAndReplaceOptions
): Promise<ModifyResult<TSchema>>;
): Promise<WithId<TSchema> | null>;
async findOneAndReplace(
filter: Filter<TSchema>,
replacement: WithoutId<TSchema>
): Promise<ModifyResult<TSchema>>;
): Promise<WithId<TSchema> | null>;
async findOneAndReplace(
filter: Filter<TSchema>,
replacement: WithoutId<TSchema>,
Expand Down Expand Up @@ -898,11 +898,11 @@ export class Collection<TSchema extends Document = Document> {
filter: Filter<TSchema>,
update: UpdateFilter<TSchema>,
options: FindOneAndUpdateOptions
): Promise<ModifyResult<TSchema>>;
): Promise<WithId<TSchema> | null>;
async findOneAndUpdate(
filter: Filter<TSchema>,
update: UpdateFilter<TSchema>
): Promise<ModifyResult<TSchema>>;
): Promise<WithId<TSchema> | null>;
async findOneAndUpdate(
filter: Filter<TSchema>,
update: UpdateFilter<TSchema>,
Expand Down
5 changes: 2 additions & 3 deletions src/operations/find_and_modify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ export interface FindOneAndDeleteOptions extends CommandOperationOptions {
/** Map of parameter names and values that can be accessed using $$var (requires MongoDB 5.0). */
let?: Document;
/**
* Return the ModifyResult instead of the modified document. Defaults to true
* but will default to false in the next major version.
* Return the ModifyResult instead of the modified document. Defaults to false
*/
includeResultMetadata?: boolean;
}
Expand Down Expand Up @@ -142,7 +141,7 @@ class FindAndModifyOperation extends CommandOperation<Document> {
upsert: false
};

options.includeResultMetadata ??= true;
options.includeResultMetadata ??= false;

const sort = formatSort(options.sort);
if (sort) {
Expand Down
8 changes: 5 additions & 3 deletions test/integration/crud/crud_api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ describe('CRUD API', function () {
it('returns the modify result', async function () {
const result = await collection.findOneAndDelete(
{ a: 1 },
{ projection: { b: 1 }, sort: { a: 1 } }
{ projection: { b: 1 }, sort: { a: 1 }, includeResultMetadata: true }
);
expect(result?.lastErrorObject.n).to.equal(1);
expect(result?.value.b).to.equal(1);
Expand Down Expand Up @@ -685,7 +685,8 @@ describe('CRUD API', function () {
projection: { b: 1, c: 1 },
sort: { a: 1 },
returnDocument: ReturnDocument.AFTER,
upsert: true
upsert: true,
includeResultMetadata: true
}
);
expect(result?.lastErrorObject.n).to.equal(1);
Expand Down Expand Up @@ -742,7 +743,8 @@ describe('CRUD API', function () {
projection: { b: 1, d: 1 },
sort: { a: 1 },
returnDocument: ReturnDocument.AFTER,
upsert: true
upsert: true,
includeResultMetadata: true
}
);
expect(result?.lastErrorObject.n).to.equal(1);
Expand Down
8 changes: 6 additions & 2 deletions test/integration/crud/explain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe('CRUD API explain option', function () {
{
name: 'findOneAndDelete',
op: async (explain: boolean | string) =>
await collection.findOneAndDelete({ a: 1 }, { explain })
await collection.findOneAndDelete({ a: 1 }, { explain, includeResultMetadata: true })
},
{
name: 'findOne',
Expand All @@ -52,7 +52,11 @@ describe('CRUD API explain option', function () {
{
name: 'findOneAndReplace',
op: async (explain: boolean | string) =>
await collection.findOneAndReplace({ a: 1 }, { a: 2 }, { explain })
await collection.findOneAndReplace(
{ a: 1 },
{ a: 2 },
{ explain, includeResultMetadata: true }
)
},
{
name: 'aggregate',
Expand Down
Loading