I am doing some aggregation on a mongo 2.4.9 collection but I am not able to sort the result by two fields. Here is the query I am making using PyMongo:
result = mongo_coll.aggregate([{"$match": {"_cls": "class1"},
{"$group": {"_id": {"currency": "$total.currency",
"v_id": "$v_id"},
"total": {"$sum": "$total.amount"},
"count": {"$sum": 1}}},
{"$sort": {"_id.currency": 1, "total": -1}}])
And I have the result sorted ONLY by "total":-1
If I replace the last line with the following:
{"$sort": {"total": -1, "_id.currency": 1}}])
It is still sorted by "total":-1
And if I replace it with the following:
{"$sort": {"_id.currency": 1}}])
It gets sorted by currency.
But I can't get it sorted how I want, which means by currency first, and then by total... (The results else look good, as expected). Anybody has a clue ?
Here is a sample doc:
{
"_id": { "$oid" : "533d0a3b830f783478a75aa1" },
"_cls": "class1",
"v_id": 6813,
"total": {
"amount": 680,
"currency": "EUR",
"exp": -2
}
}
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/ec9665b8-ffaf-42b4-908d-f4d5a7b0f047%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.