With this given data.
{ "_id" : 0, "a" : 0, "b" : 0, "c" : 21 }
{ "_id" : 1, "a" : 0, "b" : 0, "c" : 54 }
{ "_id" : 2, "a" : 0, "b" : 1, "c" : 52 }
{ "_id" : 3, "a" : 0, "b" : 1, "c" : 17 }
{ "_id" : 4, "a" : 1, "b" : 0, "c" : 22 }
{ "_id" : 5, "a" : 1, "b" : 0, "c" : 5 }
{ "_id" : 6, "a" : 1, "b" : 1, "c" : 87 }
{ "_id" : 7, "a" : 1, "b" : 1, "c" : 97 }
The query is this
db.fun.aggregate([{
$group: {
_id: { a: "$a", b: "$b" },
c: { $max: "$c" }
}
}, {
$group: {
_id: "$_id.a",
c: { $min: "$c" }
}
}])
The correct answer is
54 and 22
How come is it like that? I was expecting to be 97 and 21
Why have I thought of 97 as max and 21 as min? becaus all of the documents that has a similar values(namely a and b) c is the highest and the lowest is 21
can someone eloborate this to me? and how $group really work?
52 and 22, not54 and 22.