2015-11-19 122 views
1

我已经在去建立一个程序以一个结构存储切片和嵌套结构MongoDB中Golang

type A struct { 
    feature []string 
} 

type B struct { 
    title string 
    other_feature []A 
} 

我试图用BSON包,但只有标题出现执行后的数据库上。有没有人有办法解决吗?

+2

你能分享更多的代码/请注明您所使用的 – bvpx

+0

可能的复制蒙戈DB驱动程序[golang mongodb的氧化镁(MgO)未插入文档(http://stackoverflow.com/questions/33045404/ golang-mongodb的-MgO的是 - 不插入-文档) –

回答

3

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

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

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