Skip to content
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

document.prototype.$set does not allow merging of subdocuments #8201

Closed
m-weeks opened this issue Sep 26, 2019 · 0 comments
Closed

document.prototype.$set does not allow merging of subdocuments #8201

m-weeks opened this issue Sep 26, 2019 · 0 comments
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Milestone

Comments

@m-weeks
Copy link

m-weeks commented Sep 26, 2019

Do you want to request a feature or report a bug?
Bug

What is the current behavior?
Calling .set on the parent model with the merge option set to true, does not merge subdocuments.

If the current behavior is a bug, please provide the steps to reproduce.
Sample Schema:

var AddressSchema = new mongoose.Schema(
  {
    street: { type: String, required: true },
    city: { type: String, required: true },
    country: { type: String, required: true },
  }
);

var PersonSchema = new mongoose.Schema(
  {
    name: { type: String, required: true },
    address: { Type: AddressSchema, required: true },
  }
);

var Person = mongoose.model('Person', PersonSchema);

With a Person already stored as:

{
  _id: '5d8d2525c1631200550cea41',
  name: 'John Bastion',
  address: {
    _id: '5d7f9ab3f1a6120607784451',
    street: 'Real Street',
    city: 'Vancouver',
    country: 'Canada',
  }
}

And if I call something like the following:

// person is a document
person.set({ name: 'John Bastien', address: { street: 'Fake Street' } }, undefined, { merge: true });
await person.save();

Address is set to simply { street: 'Fake Street' } and is not merged.
It might be worth noting too that person.address.isNew is still false however

What is the expected behavior?
The person object should be updated to:

{
  _id: '5d8d2525c1631200550cea41',
  name: 'John Bastien',
  address: {
    _id: '5d7f9ab3f1a6120607784451',
    street: 'Fake Street',
    city: 'Vancouver',
    country: 'Canada',
  }
}

What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Mongoose: 5.7.1
Mongodb: 4.0.6

@vkarpov15 vkarpov15 added this to the 5.7.4 milestone Sep 30, 2019
@vkarpov15 vkarpov15 added the has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue label Sep 30, 2019
vkarpov15 added a commit that referenced this issue Oct 1, 2019
@vkarpov15 vkarpov15 added confirmed-bug We've confirmed this is a bug in Mongoose and will fix it. and removed has repro script There is a repro script, the Mongoose devs need to confirm that it reproduces the issue labels Oct 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Projects
None yet
Development

No branches or pull requests

2 participants