type Player struct {
id bson.ObjectId
test map[int]int
}
func (this *Player) Id() bson.ObjectId {
return this.id
}
func (this *Player) DbObj() bson.D {
testBson := bson.D{}
for k,v := range this.test {
testBson = append(testBson, bson.M{"id":k, "v":v}) // compile error
}
return bson.D{
{"_id",this.id},
{"test", testBson},
}
}
The bson document should be:
{'_id':ObjectId(xx),'test':[{'id':1,'v':1},..., {'id':2,'v':2}]}
But I don't know how to convert the map object to [{'id':1,'v':1},..., {'id':2,'v':2}]
, bson.M is not the type DocElem which D contain