Q:

In Mongodb, how do I first sort by score, then sort by time if there is a "tie"?

results = docDB.posts.find({"active":True }).sort("pop_score", pymongo.DESCENDING)

This is my sort right now. But the problem is, some things have the same "score". In that case, if they tie, I want them to sort by "time" within the ones who tied.
How do I do that? It's possible to do that in Mysql...

A:

You can sort by more than one attribute at a time. e.g.
sort({name : 1, age : -1})

will sort by name ascending then by age descending
See here for reference: http://www.mongodb.org/display/DOCS/Sorting+and+Natural+Order
Edit:
In pymongo, that would be
.sort([['name', pymongo.ASCENDING], ['age', pymongo.DESCENDING]])

referenceL http://api.mongodb.org/python/current/api/pymongo/cursor.html#pymongo.cursor.Cursor.sort

