Simply use:
pipeline = append(pipeline, bson.M{
"$match": bson.M{
"subscriptions": bson.M{"$elemMatch": bson.M{"premium": true}},
},
})
No need to check if it exists, it must, else it cannot have an element with premium=true
.
And if you have only this one condtion to the element, you may also simplify it to:
pipeline = append(pipeline, bson.M{
"$match": bson.M{"subscriptions.premium": true},
})
CLICK HERE to find out more related problems solutions.