使用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)])