[GODRIVER-2260] UpdateMany doesn't support links to existing fields Created: 28/Dec/21  Updated: 27/Oct/23  Resolved: 20/Jan/22

Status: Closed
Project: Go Driver
Component/s: Core API
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Unknown
Reporter: Apocalypsy . Assignee: Benji Rewis (Inactive)
Resolution: Gone away Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File setfieldinupdate.go    

 Description   

Summary

Go driver's UpdateMany doesn't update fields using existing fields in object.
 
col.UpdateMany(ctx,bson.M{“id”:123},bson.D{"$set", bson.D{“PreviousRecord”,"$CurrentRecord")}}

This command will update object:
{{

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

}}

as:
{{

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

}}

MongoDB 4.4 (docker image mongo:4.4); GO-driver 1.7.1

 

 



 Comments   
Comment by PM Bot [ 20/Jan/22 ]

There hasn't been any recent activity on this ticket, so we're resolving it. Thanks for reaching out! Please feel free to comment on this if you're able to provide more information.

Comment by Benji Rewis (Inactive) [ 05/Jan/22 ]

Hello again, slavik-undead@mail.ru. As of MongoDB 4.4, update functions (such as the UpdateMany you're using), can now be used with aggregation pipelines and their associated stages. To use $set with UpdateMany as you've done above, you'll have to make sure the "update" parameter to UpdateMany is actually an aggregation pipeline. In other words, the "update" parameter must be an array not a single document. You should get the behavior you're looking for if you encase the bson.D containing the $set with a bson.A. I've attached an example of how that might look given your example code. Let me know if that works!

setfieldinupdate.go

Comment by Benji Rewis (Inactive) [ 04/Jan/22 ]

Thanks for your bug report, slavik-undead@mail.ru! We're taking a look now.

Generated at Thu Feb 08 08:38:11 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.