I have a MongoDB collection like this:
{
id: "213",
sales : {
'2014-05-23': {
sum: 23
},
'2014-05-22': {
sum: 22
}
}
},
{
id: "299",
sales : {
'2014-05-23': {
sum: 44
},
'2014-05-22': {
sum: 19
}
}
},
I'm looking for a query to get all documents in my collection sorted by sum (document with the largest sum on top...).
For the example data it should return something like this:
{
id: "299",
sales : {
'2014-05-23': {
sum: 44
},
'2014-05-22': {
sum: 19
}
}
},
{
id: "213",
sales : {
'2014-05-23': {
sum: 23
},
'2014-05-22': {
sum: 22
}
}
},
Because: the sum 44 is the largest, therefore this document in the collection shows first.
Is that possibly (and fast enough)? Else I can redesign the database - maybe someone has a suggestion for that?