私はイオンアプリを作成しましたが、現在Goを経由してMongoDBから配列を取得しようとしています。これは、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 []}
「結果」の定義を表示する質問を更新してください。 –
エラーがありますか? – JimB
エラーはありません。空の配列ではなく配列を返すことを意図しています – Racket