Here is an example of the document I'm working on:
{
"_id" : ObjectId("5b35019563726438989381d3"),
"ref" : "123",
"nom" : "pc",
"Revendeurs" : [
{
"revendeur" : "Tdiscount",
"selecteur_prix" : ".price",
"hist_prix" : [
{
"date" : ISODate("2018-06-28T00:00:00Z"),
"prix" : 200
},
{
"date" : ISODate("2018-06-27T00:00:00Z"),
"prix" : 100.8}
]
}
]
}
I want to query the max of 'prix' field. I need also to list all the 'prix' by 'revendeur' but Mongodb is returning only empty result.
When executing this query :
db.Tunicompare.aggregate([
{ $unwind: '$Revendeurs' },
{ $group: { _id: null, max: { $max: '$Revendeurs.hist_prix.prix' } } },
{ $project: { max: 1, _id:0 } }
])
I get this result (instead of getting only 200 as a maximum)
{ "max" : [ 200, 100.8 ] }