Pymongo: TypeError: if no direction is specified, key_or_list must be an instance of list

来源:互联网 发布:如何更新mac os系统 编辑:程序博客网 时间:2024/06/10 01:12

使用pymongo对某一字段进行sort时,报错 

TypeError: if no direction is specified, key_or_list must be an instance of list

问题代码:

items = db.symptomAssociation.find({ 'result.pre.0':{'$regex':input_text}}).sort({'result.0.confidence':-1})

更正后:

items = db.symptomAssociation.find({ 'result.pre.0':{'$regex':input_text}}).sort([('result.0.confidence',-1)])

2 1