I'd like to use the $max operator in an aggregate but an ID is needed if I use a group.
My documents have this kind of structure:
{
"_id" : ObjectId("5633d6c3425d449c2ed498dd"),
"stuff" : 123,
"names" : [
{
"type" : "primary",
"value" : "Foobar"
},
{
"type" : "alternate",
"value" : "Lorem Ipsum"
},
{
"type" : "alternate",
"value" : "Bar foo"
}
]
}
I tried to use a $max without group
db.foobar.aggregate([
{ $unwind: "$names" },
{ $max: "$names.value" }
]);
But get "exception: Unrecognized pipeline stage name: '$max'"
And also tried:
db.foobar.aggregate([
{ $unwind: "$names" },
{
$group:
{
_id: "",
maxName: { $max: "$names.value" }
}
}
]);
But get
{
"_id" : "",
"maxName" : "7つの紋章、7つの部族"
}
Which is weird because I have strings with latin alphabet really longer such as : "Middleton's New Geographical Game of a Tour through England and Wales"
Am I missing something? Do you have any idea how can I use this $max?