【发布时间】:2017-07-12 22:36:52
【问题描述】:
我创建了一个 ionic 应用程序,我目前正试图通过 Go 从 MongoDB 检索一个数组。这就是 MongoDB 中的数据的样子。
{
"_id": {
"$oid": "58a86fc7ad0457629d64f569"
},
"name": "ewds",
"username": "affe@dsg.com",
"password": "vdseaff",
"email": "fawfef",
"usertype": "Coaches",
"Requests": [
"test@t.com"
]
}
我目前正在尝试取回请求字段,其中一种方法是尝试使用以下代码接收整个文档。
//this is the struct being used.
type (
User struct {
Name string
Username string
Password string
Email string
UserType string
Requests []string
}
)
results := User{}
err = u.Find(bson.M{"username": Cname}).One(&results)
这仅返回带有空数组的以下内容。
{ewds affe@dsg.com vdseaff fawfef Coaches []}
【问题讨论】:
-
更新问题以显示
results的定义。 -
有错误吗?
-
没有错误。它的意思是返回数组而不是空数组
标签: arrays mongodb go ionic-framework