I need to group and sort by date_published some documents stored on mongodb using pymongo.
the group part went just fine 🙂 but when I’m addding .sort() to the query it keeps failing no matter what I tried 🙁
here is my query:
db.activities.group(keyf_code,cond,{},reduce_code)
I want to sort by a field called “published” (timestamp)
tried to do
db.activities.group(keyf_code,cond,{},reduce_code).sort({"published": -1})
and many more variations without any success
ideas anyone?
You can’t currently do sort with group in MongoDB. You can use MapReduce instead which does support a sort option. There is also an enhancement request to support group with sort here.