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