How to sort mongodb with pymongo

前端 未结 7 1836
情书的邮戳
情书的邮戳 2020-11-28 04:01

I\'m trying to use the sort feature when querying my mongoDB, but it is failing. The same query works in the MongoDB console but not here. Code is as follows:



        
7条回答
  •  萌比男神i
    2020-11-28 04:43

    Say, you want to sort by 'created_on' field, then you can do like this,

    .sort('{}'.format('created_on'), 1 if sort_type == 'asc' else -1)
    

提交回复
热议问题