我的 mongo db 中有与此文档类似的文档
{
"_id": ObjectId("5cbf416ec6490b9baff4d284"),
"rewards" : [
{
"percent" : NumberLong(100),
"promotion_id" : "promotest"
}
],
"eligible_for": ["XYZ","ABC"]
}
当我使用正确的文档进行更新时,它会正确更新文档
但是当我通过奖励时,qualified_for 为 null,然后qualified_for 更新为 null 但奖励未更新为 null
{
"rewards" : null,
"eligible_for": null
}
然后是新更新的文档
{
"_id": ObjectId("5cbf416ec6490b9baff4d284"),
"rewards" : [
{
"percent" : NumberLong(100),
"promotion_id" : "promotest"
}
],
"eligible_for": null
}
这是我用来使用 mongo-go-driver 更新文档的查询。
r.PollingGameCollection.UpdateOne(ctx, bson.M{"_id": poll.RawId}, M{"$set": poll})
对象是:
type PollingGame struct {
RawId *objectid.ObjectID `json:"-" bson:"_id,omitempty"`
Rewards *[]Reward `json:"rewards,omitempty" bson:"rewards,omitempty"`
EligibleFor []string `json:"eligible_for,omitempty" bson:"eligible_for, omitempty"`
}
type Reward struct {
Percent int `json:"percent,omitempty" bson:"percent,omitempty"`
PromotionId string `json:"promotion_id,omitempty" bson:"promotion_id,omitempty"`
}