You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have searched existing issues to ensure the bug has not already been reported
Mongoose version
7.2.1
Node.js version
14.17.3
MongoDB server version
6.0.5
Typescript version (if applicable)
No response
Description
Based on my analysis, it appears that there are some issues with the findOneAndReplace method when using the strict option. Specifically, the function using findOneAndUpdate method throws an error during execution, while the replace function using findOneAndReplace works without any problems.
Upon reviewing the situation, it seems that the {strict: 'throw'} option of findOneAndReplace is not overriding the {strict: true} property of the schema as it is intended to, similar to how it works in findOneAndUpdate. It is unclear why the {strict: 'throw'} option in findOneAndReplace is not being patched.
Error Message:
> put data
Connected to MongoDB
replace result: { _id: new ObjectId("64884ad808a564d77dc37bf7") }
> patch data
Connected to MongoDB
Error: StrictModeError: Field `x` is not in schema and strict mode is set to throw.
at walkUpdatePath (/Users/kushagra/gridfs/node_modules/mongoose/lib/helpers/query/castUpdate.js:348:17)
at castUpdate (/Users/kushagra/gridfs/node_modules/mongoose/lib/helpers/query/castUpdate.js:92:7)
at model.Query._castUpdate (/Users/kushagra/gridfs/node_modules/mongoose/lib/query.js:4673:10)
at model.Query._findOneAndUpdate (/Users/kushagra/gridfs/node_modules/mongoose/lib/query.js:3302:23)
at model.Query.exec (/Users/kushagra/gridfs/node_modules/mongoose/lib/query.js:4404:28)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async update (/Users/kushagra/gridfs/index.js:53:21)
at async /Users/kushagra/gridfs/index.js:78:29 {
isImmutableError: false,
path: 'x'
}
Prerequisites
Mongoose version
7.2.1
Node.js version
14.17.3
MongoDB server version
6.0.5
Typescript version (if applicable)
No response
Description
Based on my analysis, it appears that there are some issues with the
findOneAndReplace
method when using the strict option. Specifically, the function usingfindOneAndUpdate
method throws an error during execution, while the replace function usingfindOneAndReplace
works without any problems.Upon reviewing the situation, it seems that the
{strict: 'throw'}
option offindOneAndReplace
is not overriding the{strict: true}
property of the schema as it is intended to, similar to how it works infindOneAndUpdate
. It is unclear why the{strict: 'throw'}
option infindOneAndReplace
is not being patched.Error Message:
Sample Data
Steps to Reproduce
Run the provided code.
Expected Behavior
Both the replace and update functions should work as intended by throwing the errors by overriding the option in the schema.
The text was updated successfully, but these errors were encountered: