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

2019-02-14 16:34:40 浏览数 (1)

使用pymongo对某一字段进行sort时,报错 TypeError: if no direction is specified, key_or_list must be an instance of list 问题代码:在mongo中执行没有问题

代码语言:javascript复制
count=db.three_province_poi_v9.find({ "sum_n.sum_4_x":{ $gt:0} } ).sort({"sum_n.sum_4_x":1}). count()

更正后:在python中执行

代码语言:javascript复制
count=db_first.three_province_poi_v9.find({"sum_n.sum_4_x":{ "$gt":0} } ).sort([("sum_n.sum_4_x",1)]).count()

附:相关代码

代码语言:javascript复制
from pymongo import MongoClient

def 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 人点赞