如何使用mongodb-go驱动程序指定多重更新选项



根据文档,我需要在某些操作中使用multi选项一次更新多个文档(示例(。

我的项目在Go中。尽管如此,当我阅读驱动程序文档时,我找不到任何multi选项。以下是提供可用选项的结构(官方go驱动程序代码(:

type UpdateOptions struct {
ArrayFilters *ArrayFilters
BypassDocumentValidation *bool
Collation *Collation
Comment interface{}
Hint interface{}
Upsert *bool
Let interface{}
}

怎么还能在我的围棋项目中使用它?

请参阅有关更新many:的文档

您可以使用UpdateMany((方法更新集合中的多个文档。

文档示例:

coll := client.Database("sample_airbnb").Collection("listingsAndReviews")
filter := bson.D{{"address.market", "Sydney"}}
update := bson.D{{"$mul", bson.D{{"price", 1.15}}}}
result, err := coll.UpdateMany(context.TODO(), filter, update)
if err != nil {
panic(err)
}

最新更新