-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
modifiedpaths are not returning as expected when we use .set() with nested paths as an object in v5.12.5 vs v6.x.x #14024
Comments
We observed another thing non-modified paths are showing as modified paths for more info please refer to the below code.
Output with v5.12.5 :
Output with v6.12.1 :
|
@vkarpov15 Can you please update the status of this tracker |
confirmed for both const mongoose = require('mongoose');
const { Schema } = mongoose;
// for function run()
/*
const eventSchema = new Schema({
name: { type: String },
__stateBeforeSuspension: {
field1: { type: String },
field2: { type: String },
jsonField: {
name: { type: String }
}
}
});*/
// for function test
const eventSchema = new Schema({
name: { type: String },
__stateBeforeSuspension: {
field1: { type: String },
field2: { type: String },
jsonField: {
name: { type: String },
name1: { type: String }
}
}
})
const Event = mongoose.model('Event', eventSchema)
async function run() {
await mongoose.connect('mongodb://localhost:27017');
await mongoose.connection.dropDatabase();
const eventObj = new Event({ name: 'event object', __stateBeforeSuspension: { field1: 'test', jsonField: { name: 'test3' }} })
eventObj.save(function (err, eventObj) {
var newObject = eventObj.toObject()
newObject.__stateBeforeSuspension = { field1: '12', jsonField: { name: 'test4' }}
eventObj.set(newObject)
var modifiedPaths = eventObj.modifiedPaths()
console.log(modifiedPaths)
})
}
// run();
async function test() {
await mongoose.connect('mongodb://localhost:27017');
await mongoose.connection.dropDatabase();
const eventObj = new Event({ name: "event object", __stateBeforeSuspension: { field1: "test", jsonField: { name: "test3" }} })
eventObj.save(function (err, eventObj) {
var newObject = { field1: "test", jsonField: { name: "test3", name1: "test4"} }
eventObj.set('__stateBeforeSuspension', newObject)
var modifiedPaths = eventObj.modifiedPaths()
console.log(modifiedPaths)
})
}
test(); |
For your first post (the following code snippet), this is expected behavior. In Mongoose 6,
Re: your 2nd post, the fact that |
@vkarpov15 For the first use case, it's working as expected but we found that we are using
Output with v5.12.5 :
Output with v6.12.1 :
If we see the above outputs we are not getting the as-expected values for the "direct modified path" log |
I think the |
@vkarpov15 We are using |
Does using |
@vkarpov15, No it doesn't work as |
What is your definition of the exact fields that were modified? Do you have a more exact definition or just the 5.x behavior? |
As mentioned in this comment #14024 (comment) we are updating the '__stateBeforeSuspension.jsonField.name' and '__stateBeforeSuspension.field1' fields those fields are not coming as the |
Just adding to what @sakethyerra mentioned, @vkarpov15 |
@vkarpov15, Any update on this |
Hi, I'm confirming that the |
@heyfirst can you please clarify what sort of issues you're seeing? |
This issue is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 5 days |
Hi @vkarpov15, our problem is that when we push the item to the array of subdocuments, it's marked as modified the whole array. in v5, it will marked modified only the one that has been added. you can see the code below which's from ![]() We have 2 schema, let's say This issue made us really difficult to move to Mongoose v6. I have checked the code on isModified itself and seems like it has a slightly changes from v5 and v6 as v6 seems checking the parents modified path as well. I might be wrong and hope you could also guide me to implement the proper way to use isModified here. Sorry for a very late reply 🙇🏻 , I was in vacay and recently come back to work. I also see #14149 that mentioned about using Mongoose v5 in mongodb v5 too and if it is possible, we may stay a little bit longer on v5 and see if our codebase can adapt to align with the functionality of v6 or any other relevant changes. |
@vkarpov15 I will create the reproduce script for you in first week of January 🫡 hope it will help you easily reproduce the issue. |
@heyfirst thanks for the repro, we will look into it and see if we can fix |
…mpatibility with Mongoose 5 Re: #14024
Sure! let me try them by this evening! Thanks so much for promptly act on it 🙇🏻 by the way, Happy New Year! Wishing you joy and success in the coming year. Cheers to unforgettable moments and exciting adventures ahead! |
fix: add ignoreAtomics option to isModified() for better backwards compatibility with Mongoose 5
Prerequisites
Mongoose version
6.12.1
Node.js version
14.18.1
MongoDB server version
4.4
Typescript version (if applicable)
No response
Description
Hi, the following code behaves differently in both versions v5.12.5 and v6.x.x.
Note: modified paths are not returning as expected when we use .set() with nested paths as an object.
Output with v5.12.5 :
Output with v6.12.1 :
The modified paths are returning differently in both versions.
Note: We have raised a different issue similar to .set() one. for more info please refer to #14022
Steps to Reproduce
Added the full-fledged details on how to reproduce the issue in the description with a code snippet.
Expected Behavior
No response
The text was updated successfully, but these errors were encountered: