Error. update document must contain key beginning with '$'

I update golang client version from v1.3.5 to v1.5.2.
But I find there has failed in using.

	model := mongo.NewUpdateOneModel().SetFilter(
		bson.M{
			"anchorLotteryID": awardInfo.LotteryID,
			"uin":             winner,
		},
	).SetUpdate(winningRecord).SetUpsert(true)

This is my old using. It failed and error is “update document must contain key beginning with ‘$’”

So,I change it to

	model := mongo.NewUpdateOneModel().SetFilter(
		bson.M{
			"anchorLotteryID": awardInfo.LotteryID,
			"uin":             winner,
		},
	).SetUpdate(bson.M{"$set": winningRecord}).SetUpsert(true)

I think it is very important to compatible with old version!!!

Hi @Bo_Jiang and welcome in the MongoDB Community :muscle: !

Update operation changed in MongoDB 4.2: https://docs.mongodb.com/manual/reference/method/db.collection.updateOne/#update-with-an-aggregation-pipeline.

Now updateOne can take an aggregation. It wasn’t possible before.

They also apparently resolved the trap that many people were falling into:

> db.coll.updateOne({name:"Maxime"}, {surname: "Beugnet"})

This command, that doesn’t work anymore, was actually overwriting the entire document with {name:"Maxime"} which is what the replaceOne command is actually doing.

The actual command should be either

> db.coll.replaceOne({name:"Maxime"}, {surname: "Beugnet"})
OR
> db.coll.updateOne({name:"Maxime"}, {$set: {surname: "Beugnet"}})

So, to me, it’s normal and expected that the following command fails and raises an error.

> db.coll.updateOne({name:"Maxime"}, {surname: "Beugnet"})

At least this resolve the confusion between the 2 commands and hopefully people won’t erase their entire document when they are actually just trying to add a new field in them or set an existing field to a new value.

Cheers,
Maxime.