Hu_XiaoYu
(Hu Xiao Yu)
July 25, 2022, 6:43am
1
I used Mongo version 4.2.3, go-driver version 1.9.1
I succeeded when I executed the command in the Mongo shell, but failed consistently when I used go-driver
Here are the commands I executed in the Mongo shell:
db.tbl. update({}, [{$set: {'labels_bak': '$labels'}}], {"multi": true})
Here’s The go code I’m writing:
update := bson.M{
"$set": bson.M{
"labels_bak": "$labels",
},
}
Hello @Hu_XiaoYu , welcome to the MongoDB Community forum!
You can try this code:
filter := bson.D{{}}
pipe := bson.D{{ "$set", bson.D{{ "labels_bak", "$labels"}} }}
updateResult, err := collection.UpdateMany(ctx, filter, mongo.Pipeline{ pipe })
Note the usage of the mongo.Pipeline
when using the Updates with Aggregation Pipeline.
2 Likes
Hu_XiaoYu
(Hu Xiao Yu)
July 25, 2022, 12:18pm
3
Thank you for your answer. It was very helpful to me!
system
(system)
Closed
July 30, 2022, 12:19pm
4
This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.