2 回答
TA贡献2039条经验 获得超7个赞
有了这个包,go.mongodb.org/mongo-driver/mongo你可以这样做:
coll.FindOneAndUpdate(
context.Background(),
bson.D{
{"id", "1234"},
{"achievements.scope", "life achievements"},
{"achievements.list._id", 1},
},
bson.M{"$set": bson.M{"achievements.$.list.$[elem].title": "some new test"}},
options.FindOneAndUpdate().SetArrayFilters(options.ArrayFilters{
Filters: []interface{}{bson.M{"elem._id": 1}},
}),
)
将其“翻译”为 shell:
db.user.findOneAndUpdate(
{"id": "1234","achievements.scope": "life achievements","achievements.list._id": 1},
{$set: {"achievements.$.list.$[elem].title": "some new test"}},
{arrayFilters: [{"elem._id": 1}]}
)
TA贡献2080条经验 获得超4个赞
doc := coll.FindOneAndUpdate(
context.Background(),
bson.D{
{"_id", "1234"},
{"achievements.scope", "life achievements"},
},
bson.D{
{"$set", bson.D{
{"achievements.$.list.$[elem].title", "some new text"},
}},
},
options.FindOneAndUpdate().SetArrayFilters(options.ArrayFilters{
Filters: []interface{}{bson.D{
{"elem._id", 1},
}},
}).SetReturnDocument(1),
)
- 2 回答
- 0 关注
- 142 浏览
添加回答
举报