我正在使用https://github.com/mongodb/mongo-go-driver
我正在尝试查询MongoDB。我的代码看起来
type ApiList struct {
Key string `json:"key"`
Host string `json:"host"`
}
type resultObj struct {
Email string `json:"email"`
UserName string `json:"user_name"`
Quota int32 `json:"quota"`
LastLogin string `json:"last_login"`
Usage int32 `json:"usage"`
ApiKeys []ApiList `json:"api_keys"`
}
var result = &resultObj{}
filter := bson.M{"email": emailId}
ctx, _ = context.WithTimeout(context.Background(), 5*time.Second)
err = database.Collection(collectionName).FindOne(ctx, filter).Decode(result)
问题是
结果对象仅具有Quota
和Usage
的值。
其余字段为空字符串。
我不确定我在做什么错。