When I write like this
db.Profiles.find({ userId:4790, "p2l.listId":31618 }, { "p2l.$": 1 } )
I get the desired result
...
{
"_id" : ObjectId("56052d35df3e5e564f770ed0"),
"p2l" : [
{
"listId" : 31618,
"status" : 131
}
] }
{
"_id" : ObjectId("56052d25df3e5e564f770ecd"),
"p2l" : [
{
"listId" : 31618,
"status" : 25
}
] }
{
"_id" : ObjectId("56052d1adf3e5e564f770eca"),
"p2l" : [
{
"listId" : 31618,
"status" : 25
}
] }
{
"_id" : ObjectId("5603c882bd1f3d3668ba7352"),
"p2l" : [
{
"listId" : 31618,
"status" : 24
}
] }
, but I have to group it by status
How I can do it?
I try as
db.Profiles.aggregate( {$match:{ userId:4790, "p2l.listId":31618}},
{$project:{"p2l.listId":"$p2l.listId", "p2l.status":"$p2l.status"}} )
but in rezult, I have values, that do not meet the parameters of the request. As a result, there listId = 31617
{
"result" : [
...
{
"_id" : ObjectId("56052d25df3e5e564f770ecd"),
"p2l" : [
{
"listId" : [
31618
],
"status" : [
25
]
}
]
},
{
"_id" : ObjectId("56052d1adf3e5e564f770eca"),
"p2l" : [
{
"listId" : [
31618,
31617
],
"status" : [
25,
25
]
},
{
"listId" : [
31618,
31617
],
"status" : [
25,
25
]
}
]
},
{
"_id" : ObjectId("5603c882bd1f3d3668ba7352"),
"p2l" : [
{
"listId" : [
31618
],
"status" : [
24
]
}
]
}
],
"ok" : 1.0000000000000000,
"$gleStats" : {
"lastOpTime" : Timestamp(0, 0),
"electionId" : ObjectId("5606384b5e0803423d340427")
}
}