2011-02-09 6 views

risposta

13

È possibile ordinare per più di un attributo alla volta. per esempio.

sort({name : 1, age : -1}) 

sarà ordinare per nome ascendente poi per età decrescente

Vedi qui per riferimento: http://www.mongodb.org/display/DOCS/Sorting+and+Natural+Order

Edit:

In pymongo, che sarebbe

.sort([['name', pymongo.ASCENDING], ['age', pymongo.DESCENDING]]) 

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

+0

Come scriveresti quella domanda in Pymongo? Pymongo non accetta un dizionario. Accetta 2 argomenti – TIMEX

+0

In base alla documentazione, pymongo sort può prendere un elenco di coppie di valori chiave per ordinare http://api.mongodb.org/python/current/api/pymongo/cursor.html#pymongo.cursor.Cursor. ordinare –

Problemi correlati