为了账号安全,请及时绑定邮箱和手机立即绑定

在mongodb-go-driver中,如何将BSON编组/解组为结构

在mongodb-go-driver中,如何将BSON编组/解组为结构

Go
千巷猫影 2021-04-10 18:19:11
我是mongodb-go-driver的新手。但是我被困住了。cursor, e := collection.Find(context.Background(), bson.NewDocument(bson.EC.String("name", id)))for cursor.Next(context.Background()) {    e := bson.NewDocument()    cursor.Decode(e)    b, _ := e.MarshalBSON()    err := bson.Unmarshal(b, m[id])}当查看m [id]的内容时,它没有内容-全部为null。我的地图是这样的:m map [string] Language语言定义如下:type Language struct {    ID         string   `json:"id" bson:"_id"`                   // is this wrong?    Name       string   `json:"name" bson:"name"`    Vowels     []string `json:"vowels" bson:"vowels"`    Consonants []string `json:"consonants" bson:"consonants"`}我究竟做错了什么?我正在使用此示例进行学习:https : //github.com/mongodb/mongo-go-driver/blob/master/examples/documentation_examples/examples.go
查看完整描述

3 回答

  • 3 回答
  • 0 关注
  • 377 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信