python - pymongo sorting by date -


i want newest posts first, , try following:

db.posts.find({"date": {"$lt": tomorrow, "$gte":                 today}}).sort({'date':pymongo.descending}) 

(without sort, oldest posts first fine)

i getting error

typeerror: if no direction specified, key_or_list must instance of list 

what going on here? not possible sort date?

this not correct format of parameters sort function. correct syntax this:

db.posts.find(...).sort('date',pymongo.descending) 

here link relevant documentation sort function: http://api.mongodb.org/python/current/api/pymongo/cursor.html#pymongo.cursor.cursor.sort

to sort multiple parameters can use following syntax:

db.posts.find(...).sort([   ('date', pymongo.ascending),   ('other_field', pymongo.descending) ]): 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -