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

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章