我正在尝试检查订阅部分是否存在,以及它是否包含至少一个名为 premium 的变量,其值为 true。
如果是,它应该返回,如果不是,它不应该返回。目前它正在返回集合中的对象,即使该值设置为 false。
// query to find all the users accounts that have purchased premium subscriptions
hasPurchasedSubscriptions := c.QueryParam("hasPurchasedSubscriptions")
if hasPurchasedSubscriptions != "" {
pipeline = append(pipeline, bson.M{
"$match": bson.M{"$and": []interface{}{
bson.M{"subscriptions": bson.M{"$exists": true}},
bson.M{"subscriptions": bson.M{"$elemMatch": bson.M{"premium": true}}},
}},
})
}
})
慕村225694
相关分类