Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-2505

Update array element by index not work as expected

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Gone away
    • Icon: Major - P3 Major - P3
    • None
    • None
    • None
    • None

    Description

      Summary

      Updating array element by index adds new property to all elements with index as part of the property name

      How to Reproduce

      Let's assume we have this structure:

      {
        "foos": [{
          "bar": "value 1"
        }, {
          "bar": "value 2"
        }]
      }
      

      If we want to change "value 2" to "value 3", we can update in mongo console:

      .updateOne({_id: new ObjectId("***")}, {"$set": {"foos.1.bar":"value3"}});
      

      It works perfectly. But if I do the same thing in golang:

      .UpdateOne(ctx, bson.M{"_id": someID}, bson.A{
      		bson.M{
      			"$set": bson.M{
      				"foos.1.bar":"value 3",
      			},
      		},
      	})
      

      This will result:

      {
        "foos": [{
          "bar": "value 1",
          "1": {"bar": "value 3"}
        }, {
          "bar": "value 2",
          "1": {"bar": "value 3"}
        }]
      }
      

      Would you mind checking this? Thank you

      Attachments

        Activity

          People

            preston.vasquez@mongodb.com Preston Vasquez
            vietnamvisa.dev@gmail.com Nam Truong Le
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: