-
-
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
Unmodified fields being marked as modified. #11913
Comments
Here's another repro case. Looks like this behavior is occurring when trying to set via an object. Using the args it's fine. 'use strict';
const mongoose = require('./lib');
const person = new mongoose.Schema({
name: {
first: String,
last: String
},
haircolor: String,
eyecolor: String
});
const Person = mongoose.model('Person', person);
(async function() {
await mongoose.connect('mongodb://localhost:27017/example');
const bob = 'bob';
const h = {
name: {
first: bob,
last: 'jones'
},
haircolor: 'brown',
eyecolor: 'brown'
};
const human = new Person(h);
await human.save();
human.set('name.first', bob);
console.log(`human.isModified via args: ${human.isModified('name.first')}`);
human.set({ name: { first: bob } });
console.log(`human.isModified via obj: ${human.isModified('name.first')}`);
await mongoose.disconnect();
})(); |
@vkarpov15 It looks like 6.3.8 was released a couple hours ago, but 6.3.7 was skipped in releases though the milestone was closed, so maybe either this isn't the correct milestone, or their was an error in the version numbering? |
@jjacksonjc we had to release 6.3.8 shortly after 6.3.7, because we accidentally shipped 6.3.7 with failing tests. In Mongoose, this is exopected behavior, because So The workaround is to set the 'use strict';
const mongoose = require('mongoose');
const person = new mongoose.Schema({
name: {
first: String,
last: String
},
haircolor: String,
eyecolor: String
});
const Person = mongoose.model('Person', person);
(async function() {
await mongoose.connect('mongodb://localhost:27017/example');
const h = {
name: {
first: 'bob',
last: 'jones'
},
haircolor: 'brown',
eyecolor: 'brown'
};
const human = new Person(h);
await human.save();
h.name.first = 'Larry';
human.set(h, null, null, { merge: true });
console.log(`expect 'name,name.first': ${human.modifiedPaths({ includeChildren: true })}`);
console.log(`expect 'false': ${human.isModified('haircolor')}`);
console.log(`expect 'false': ${human.isModified('eyecolor')}`);
console.log(`expect 'true': ${human.isModified('name.first')}`);
console.log(`expect 'false': ${human.isModified('name.last')}`);
await mongoose.disconnect();
})(); Does that work for you? |
That did work, but it brings up the question: where are the available |
Prerequisites
Mongoose version
6.3.5
Node.js version
16.x
MongoDB server version
5.x
Description
When a child field is modified, all children sharing a common parent are getting marked as modified, whether or not they were actually modified. This is a deviation from mongoose v5 and lower behavior and seems to be unintentional since it doesn't appear that any unit tests are checking for this case.
Steps to Reproduce
With
mongo
listening on27017
run the following script and observe the output.Expected Behavior
In the above example
name.last
should not be marked asmodified
.The text was updated successfully, but these errors were encountered: