Mongodb query:
db.products.aggregate([
{
$match : {
"_id" : ObjectId("60d95b5ab861ccc04fd4b598")
}
},
{
$project: {
title : "Test Product 10",
offers: {
$filter: {
input: "$offers",
as: "offers",
cond: {
$eq: [ "$$offers.active", true ]
}
}
}
}
}
]).pretty()
Golang Query:
productMatch := bson.D{{"$match", bson.M{"_id": objID}}}
project := bson.D{{"$project", bson.D{{"offers", bson.D{{"$filter", bson.D{{
"input", "$offers"}, {"as", "offers"}, {"cond", bson.D{{
"$eq", bson.D{{"$$offers.active", true}}}}}}}}}}}}
pipeLine := mongo.Pipeline{productMatch, project}
result, err := s.DB.Collection(collectionProducts).Aggregate(context.TODO(), pipeLine)