My Go code is:
query := []bson.M{
bson.M{
"$match": bson.M{
"static.created": bson.M{
"$gt": someDate,
},
},
},
bson.M{
"$group": bson.M{
"_id": "$static.name",
"count": bson.M{ "$sum": 1 },
},
},
bson.M{
"$match": bson.M{
"count": bson.M{
"$gte":2,
},
},
},
bson.M{
"$project": bson.M{
"count": 1,
"static.name": 1,
},
},
}
pipe := c.Pipe(query)
response := []bson.M{}
err = pipe.All(&response)
In response I should get 3 fields: _id count static.name
But I get only two of them: _id count
How could I get additional fields in my response? I have added the field in $project but it doesn't appear in response.
I tried to remote _id field with:
bson.M{
"$project": bson.M{
"_id": 0,
"count": 1,
"static.name": 1,
},
},
and it worked. So the $project works to remove fields but it doesn't work to add them.