gpt4 book ai didi

arrays - 在 MongoDB Golang 中存储 slice 和嵌套结构

转载 作者:IT王子 更新时间:2023-10-29 01:55:12 26 4
gpt4 key购买 nike

我已经用下一个结构用 Go 构建了一个程序

type A struct {
feature []string
}

type B struct {
title string
other_feature []A
}

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

最佳答案

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

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

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

关于arrays - 在 MongoDB Golang 中存储 slice 和嵌套结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33814370/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com