I am trying to check if the slice of subscriptions exists, and also if it contains at least one variable called premium with the value of true.
If so it should return, if not it should not return. Currently it is returning the object in the collection even if the value is set to 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}}},
}},
})
}
})