1

I want to update the field editing:

{
    "_id" : "C7PgEtzToNwHgJb6e",
    "metadata" : {
        "type" : "anything",
        "editing" : false
    }
}

If I do...

Collection.update(
    { _id: id },
    { $set: { metadata: { editing: true } } }
);

... the field type will be removed:

{
    "_id" : "C7PgEtzToNwHgJb6e",
    "metadata" : {
        "editing" : true
    }
}
user3142695
  • 15,844
  • 47
  • 176
  • 332
  • https://gist.github.com/sym3tri/858142 – Lucas Pottersky Nov 24 '15 at 16:36
  • Possible duplicate of [How do I partially update an object in MongoDB so the new object will overlay / merge with the existing one](http://stackoverflow.com/questions/10290621/how-do-i-partially-update-an-object-in-mongodb-so-the-new-object-will-overlay) – Matthias A. Eckhart Nov 24 '15 at 16:45

1 Answers1

0

Using dot notation you can ensure only the field value is updated instead of the entire field:

Collection.update(
    { _id: id },
   { $set: { "metadata.editing": true } } }
);
Alex
  • 21,273
  • 10
  • 61
  • 73