-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
fix(NODE-3770): Filter type uses WithId on the schema #3053
Conversation
@dariakp Can I please get any feedback on this PR? I'd love if we can push this through soon, since the change introduced in 4.2.0 in the |
@avaly Sorry for the delay, most of the team was out last week for the U.S. Thanksgiving holiday. We should be able to get this reviewed this week. Thanks for your patience! |
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.
Thanks again for submitting this! I added some tests and removed unneeded WithId
code from the find filter type.
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.
Thanks!
How do I use the WithoutID option? I use strings, not ObjectIDs. I cannot upgrade to this version now because it breaks my code everywhere. |
There is a bug in the typings. When using the OptionalId to have it automatically use InferIdType, it is still making me use ObjectId. It will not pick up that my _id is a string export interface LogMethodLatencyModel { (method) Collection.deleteOne(filter?: Filter<Pick<LogMethodLatencyModel, "__v" | "createdAt" | "updatedAt" | "date_start" | "date_end" | "latency_ms" | "method"> & { |
@xonuzofa Hi there, thanks for reaching out. When specifying your own _id type in the collection model, you should not make it optional, because if you insert an object without specifying the _id, MongoDB will create an ObjectID type _id on your behalf, leading to an inconsistent schema in your database. The problem you are seeing is due to the way the types for the _id are currently reconciled (see NODE-3761), and you should not run into this issue if you specify the _id as required in your model. |
Even when I change this: export interface LogMethodLatencyModel { I have a helper method here:
It gives me an error here for _id being a string and not an ObjectId:
|
@xonuzofa It doesn't look like your helper method actually populates your intended schema type through the generic. Here are some examples from our typescript definition tests that demonstrate a custom _id with find: findX.test-d.ts. If you need further help with your specific use case, I recommend asking in our community forums, as we try to limit github discussions to active PRs for driver bugs and feature requests. |
Description
What is changing?
This is changing the internal definition of the
Filter
type to always applyWithId
to the givenTSchema
.FYI: I had to remove the old unused union schema unit tests, because it was throwing a TS error. I've reached out to @nbbeeken on another PR and he confirmed that we can remove those test assertions: #2972 (comment)
Is there new documentation needed for these changes?
No
What is the motivation for this change?
Closes https://jira.mongodb.org/browse/NODE-3770
See discussion in #3044
Double check the following
npm run check:lint
script<type>(NODE-xxxx)<!>: <description>