手记

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
问题代码:在mongo中执行没有问题

count=db.three_province_poi_v9.find({ "sum_n.sum_4_x":{ $gt:0} } ).sort({"sum_n.sum_4_x":1}). count()

更正后:在python中执行

count=db_first.three_province_poi_v9.find({"sum_n.sum_4_x":{ "$gt":0} } ).sort([("sum_n.sum_4_x",1)]).count()

附:相关代码

from pymongo import MongoClientdef get_COUNT():
        Client=MongoClient('192.168.1.XXX',27017)
        db_first=Client.gaode_pois
        count=db_first.three_province_poi_v9.find   ({"sum_n.sum_4_x":{ "$gt":0} } ).sort([("sum_n.sum_4_x",1)]).count()
        print(count)


0人推荐
随时随地看视频
慕课网APP