我创建了一个离子应用程序,我目前正试图从MongoDB中通过Go返回一个数组。这就是MongoDB中的数据。正在返回的空数组
{
"_id": {
"$oid": "58a86fc7ad0457629d64f569"
},
"name": "ewds",
"username": "[email protected]",
"password": "vdseaff",
"email": "fawfef",
"usertype": "Coaches",
"Requests": [
"[email protected]"
]
}
我目前正试图找回请求字段我尝试使用以下代码接收整个文档的方法之一。
//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 [email protected] vdseaff fawfef Coaches []}
更新问题以显示'results'的定义。 –
是否有错误? – JimB
没有错误。它的意思是回馈阵列不是一个空阵列 – Racket