The Compass documentation here: https://docs.mongodb.com/compass/master/documents/modify/
says "When you edit a document in List or Table view, Compass performs a findOneAndUpdate operation and updates only those fields that you have changed."
When it comes to updating arrays of subdocuments this is not true and is very misleading.
If you update a single field in a subdocument that is in an array of subdocs, then Compass replaces the whole array.
This makes using/testing Change Streams with Compass problematic, since the Change Event will contain the whole array of subdocs, rather than just the fields that the user actually changed.
It would be very useful if Compass used $set specifications in the update operation for individual fields.
Since Compass does know the name of the array field and the index of the entry in that array, generating $set's that look like:
$set: {
"mySubdocArray.7.myChangedField": newValue
}
should be quite doable.
- is related to
-
COMPASS-6011 Unable to add data to documents in Compass
- Closed
-
COMPASS-4345 Compass does a replace instead of an update when documents are edited.
- Closed
-
COMPASS-5753 JSON editor is the only way to change _id
- Open