-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(NODE-5241): add option to return modified document #3710
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
Conversation
src/operations/find_and_modify.ts
Outdated
@@ -29,6 +29,8 @@ export interface FindOneAndDeleteOptions extends CommandOperationOptions { | |||
sort?: Sort; | |||
/** Map of parameter names and values that can be accessed using $$var (requires MongoDB 5.0). */ | |||
let?: Document; | |||
/** Return the raw result document instead of the ModifyResult */ | |||
returnRawResult?: boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wanted to bring a couple of points to your attention from the ticket description so that we minimize potential back and forth in review:
Dev note:
returnRawResult
is not meant to be prescriptive - the server returns a write_ops::FindAndModifyCommandReply, internally the driver returns a ModifyResult but our flag should make it clearer as to what is being returned
API docs should clearly explain the option
It may be worth taking this back to the team for consensus on option name; once the option name is settled, it's important to make sure we set accurate expectations for what the option does. The spec compliant version of these commands returns less information than the current ModifyResult
. In the original ticket, returnRawResult = true
is intended to return what is currently ModifyResult
and returnRawResult = false
is intended to return the spec compliant version, which is equal to ModifyResult.value
.
9a3664c
to
7b75770
Compare
/** | ||
* Test findOneAndUpdate a document | ||
*/ | ||
it('shouldCorrectlyfindOneAndUpdateDocument', { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cases in this giant test case are covered in individual findAndModify tests as well as spec tests.
/** | ||
* Test findOneAndUpdate a document | ||
*/ | ||
it('Should Correctly Handle findOneAndUpdate Duplicate Key Error', { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was testing server behaviour.
metadata: { | ||
requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] } | ||
}, | ||
test: async function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think all of these topology requirements are no longer necessary. Do you want to remove the metadata
block entirely?
(same is true for all tests I think)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
|
||
findOneAndReplace(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just want to comment on this ... recursive test functions? wow. 🙁
test/types/schema_helpers.test-d.ts
Outdated
@@ -127,6 +135,41 @@ expectAssignable<SchemaWithIdNumberInterface | null>( | |||
(await interfaceNumberTestCollection.findOneAndUpdate({ a: 1 }, { a: 5 })).value | |||
); | |||
|
|||
expectAssignable<SchemaWithIdNumberType | null>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without helpful errors / describe blocks / test names, it's hard to GROK what these tests are testing. I think they're testing the return type of findOneAnd*
methods when includeResultMetadata
is false?
- should these tests live in findX.test-d.ts? They're not actually related to how we infer the collection schema (which is that this file is for I think)
- can we comment them to make it clear what they're testing? Something I've considered in the past is an anonmyous scope with a comment:
// findOneAnd* methods return the modified document when `includeResultMetadata` is false
{
expectAssignable<SchemaWithIdNumberInterface | null>(
await interfaceNumberTestCollection.findOneAndDelete({ a: 1 }, { includeResultMetadata: false })
);
...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've reverted the schema_helpers.test-d.ts changes per your comment, and simplified type testing by just adding 3 tests (1 for each method) in findX-test-d.ts and added a comment to them.
4cf8db6
to
33023ff
Compare
import { expect } from 'chai'; | ||
|
||
import { type CommandStartedEvent, MongoServerError, ObjectId } from '../../mongodb'; | ||
import { setupDatabase } from '../shared'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have any tests for includeResultMetadata = false
? I see tests for the default behavior, but nothing with includeResultMetadata
disabled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added tests with the option set to false.
Description
Adds a new option to the
findOneAnd...
family of methods,includeResultMetadata
which defaults totrue
. When set to the default, it will return aModifyResult
, when set tofalse
, it will return the actual modified document.What is changing?
includeResultMetadata
option.findOneAndReplace
,findOneAndDelete
,findOneAndUpdate
.Is there new documentation needed for these changes?
Yes
What is the motivation for this change?
NODE-5241
Release Highlight
New
includeResultMetadata
option forfindOneAnd...
family of methods.This option defaults to
true
, which will return aModifyResult
type. When set tofalse
, which willbecome the default in the next major release, it will return the modified document or
null
if nothing matched.This applies to
findOneAndDelete
,findOneAndUpdate
,findOneAndReplace
.Double check the following
npm run check:lint
scripttype(NODE-xxxx)[!]: description
feat(NODE-1234)!: rewriting everything in coffeescript