How to use existing field while updating in mongo-go-driver?

I tried to update a field by using a value of existing field in mongo-go-driver.
here is my code:

col.UpdateMany(context.TODO(),bson.M{“id”:123},bson.M{"$set":bson.M{“PreviousRecord”:"$CurrentRecord"}})

document before update:

{
   id:123,
   PreviousRecord:"old",
   CurrentRecord:"new"
}

document after update:

{
   id:123,
   PreviousRecord:"$CurrentRecord",
   CurrentRecord:"new"
}

this cmd works in mongo shell, but not for mongo-go-driver

Hi @Ji_Hua,

I tried to reproduce your results from the shell, but I wasn’t successful. The script I ran for local testing is here. I was testing against a single node replicaset with server version 4.4.1. You mentioned your command works in the shell, so can you see if my script differs from the commands you ran at all? If you want to run the script I linked, you can download it, start up a cluster, and run mongo main.js.

– Divjot

Hi Divjot,
sorry, the code I provided is golang.
here is the mongo shell code:

db.Col.updateMany(
    {"id":"123","SnoozedExpiryTime":{"$lte": ISODate('2020-12-15T20:00:00.000+00:00')}},
    [
        {"$set": {"PreviousRecord": "$CurrentRecord", "CurrentRecord":"new"}}
    ]
)

Thank you