I have documents similar to this document in my mongo db
{
"_id": ObjectId("5cbf416ec6490b9baff4d284"),
"rewards" : [
{
"percent" : NumberLong(100),
"promotion_id" : "promotest"
}
],
"eligible_for": ["XYZ","ABC"]
}
When I updated with a proper document then it is updating the document properly
But when I pass rewards, eligible_for as null then eligible_for getting updated to null but rewards not getting updated to null
{
"rewards" : null,
"eligible_for": null
}
then the newly updated document
{
"_id": ObjectId("5cbf416ec6490b9baff4d284"),
"rewards" : [
{
"percent" : NumberLong(100),
"promotion_id" : "promotest"
}
],
"eligible_for": null
}
This is the query I am using to update the document using mongo-go-driver.
r.PollingGameCollection.UpdateOne(ctx, bson.M{"_id": poll.RawId}, M{"$set": poll})
Objects are:
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"`
}