Compass replaces whole array if you update one field in an array of objects

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: Major - P3
    • 1.32.4
    • Affects Version/s: None
    • Component/s: Compass, CRUD
    • None
    • Environment:
      MongoDB v5.0.6
      Compass v1.30.1
    • 8
    • Iteration Eel, Iteration Fish
    • Not Needed
    • None

       

      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.

            Assignee:
            Anna Henningsen
            Reporter:
            Andrzej Taramina
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: