findOne没有填充结果对象

时间:2019-11-24 12:39:33

标签: mongodb go bson

我正在使用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)

问题是 结果对象仅具有QuotaUsage的值。 其余字段为空字符串。

我不确定我在做什么错。

0 个答案:

没有答案