Details
-
Task
-
Resolution: Done
-
Major - P3
-
None
-
None
-
None
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"
collection := db.Collection("profiles")
heros := Heros
{ HeroIds: []uint32\{1, 2, 3},
}
bsb, err := bson.Marshal(heros)
if err != nil
update := bsonx.Doc{
{"$set", bsonx.Document(bsonx.Doc{{"Vip", bsonx.Int32(3)}})},
{"$set", bsonx.Document(bsonx.Doc{{"Level", bsonx.Int32(10)}})},
{"$set", bsonx.Document(bsonx.Doc{{"Heros", bsb}})}, // this not work
}
res, err := collection.UpdateOne(ctx, bson.D{{"_id", id}}, update, options.Update().SetUpsert(true))
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!