-
Type:
Bug
-
Resolution: Gone away
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
None
-
None
-
None
-
None
-
None
-
None
-
None
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