I want count of sub document in array, without using $unwind and $group , if possible.
[{
"_id" : ObjectId("5aefead0227bc943df3fedff"),
"doc" : [
{
"_id" : ObjectId("5af0e877227bc943df401337"),
"shared_with" : [
{
"user_id" : ObjectId("5ad5e57b473e2606e0d443c3"),
"_id" : ObjectId("5af0e877227bc943df401339")
},
{
"user_id" : ObjectId("5adbf029b2da8e380b9321b6"),
"_id" : ObjectId("5af0e877227bc943df401338")
}
]
},
{
"_id" : ObjectId("5b4d856702d7f52974aab962"),
"shared_with" : [
{
"user_id" : ObjectId("5ac7083ce56c9d304f2fa533"),
"_id" : ObjectId("5b4d856702d7f52974aab963")
}
]
}
]
}]
above is the result i'm getting after lookup, i want to count total number of sub document ('shared_with') inside array ('doc') with documents,
so my desired output is as follow,
[{
"_id" : ObjectId("5aefead0227bc943df3fedff"),
"count":3`enter code here`
}]