【问题标题】:Store slices and nested structures in MongoDB Golang在 MongoDB Golang 中存储切片和嵌套结构
【发布时间】:2016-02-22 05:08:15
【问题描述】:

我在 Go 中构建了一个具有下一个结构的程序

type A struct {
  feature []string
}

type B struct {
  title string
  other_feature []A
}

我尝试使用 bson 包,但执行后只有标题出现在数据库中。有人有解决办法吗?

【问题讨论】:

标签: arrays mongodb go bson


【解决方案1】:

您需要通过以大写字母开头的字段名称来export 字段名称。使用 bson 字段标签指定数据库中使用的命名。

type A struct {
  Feature []string `bson:"feature"`
}

type B struct {
  Title string       `bson:"title"`
  Other_feature []A  `bson:"other_feature"`
}

【讨论】:

    猜你喜欢
    • 2014-03-25
    • 1970-01-01
    • 2018-06-13
    • 2018-08-31
    • 2019-01-02
    • 2020-08-13
    • 2013-09-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多