[GODRIVER-889] How to Collection.UpdateOne using the result of bson.Marshal? Created: 20/Mar/19 Updated: 11/Sep/19 Resolved: 21/Mar/19 |
|
| Status: | Closed |
| Project: | Go Driver |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Task | Priority: | Major - P3 |
| Reporter: | zhangzhen | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | feature | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
For example I have struct like this: type Profile struct { Vip uint32 Lvl uint32 Heros Heros }type Heros struct { HeroIds []uint32 `bson:"hids"` HeroSkills []HeroSkill `bson:"hskls"` }type HeroSkill struct { CounterSkill []string PassiveSkill []string TriggerSkill []string }
than, I want to set a record to collection using UpdateOne.
id := "alsdkfj" heros := Heros { HeroIds: []uint32\{1, 2, 3}, update := bsonx.Doc{
I don't find any way to transform []byte to bsonx.Val, so can put the result of bson.Marshal to bsonx.Doc. If I want to update complex construction conveniently,how should I do? Please help me, thanks! |
| Comments |
| Comment by Ian Whalen (Inactive) [ 21/Mar/19 ] |
|
Hey zhangzhen, you should be using bson.D rather than bsonx.Doc - that way you don't have to marshal yourself. |
| Comment by zhangzhen [ 20/Mar/19 ] |
|
I use mongo golang sdk, https://github.com/mongodb/mongo-go-driver |