Mongo Document example:
{
"_id": "128374",
"x": [
{
"i": "83847575",
"y": [
{
"i": "9389489283",
"t": "2014-04-11T20:46:57+0000"
},
{
"i": "9389489284",
"t": "2014-04-11T20:47:57+0000"
}
]
},
{
"i": "83847576",
"y": [
{
"i": "2382349385",
"t": "2014-01-15T23:43:29+0000"
},
{
"i": "9389489286",
"t": "2014-04-11T20:47:57+0000"
},
{
"i": "9389489286",
"t": "2014-04-11T20:49:57+0000"
}
]
}
]
}
How do you get the maximum number of internal arrays of 'y' for each document? The problem I'm trying to solve is to get the record with the maximum amount of "y". Thank!
The following gives me the total number of "y".
db.coll.aggregate(
{ "$unwind" : "$x" } ,
{ "$project" : { "x" : "$x" } } ,
{ "$unwind" : "$x.y" },
{ "$group" : { _id : null, number : { $sum : 1 } } } )
source
share