繁体   English   中英

Mongodb Python 中的聚合:无法腌制“SSLContext”object

[英]Mongodb aggregation in Python : cannot pickle 'SSLContext' object

我需要找到相同组的数量(例如相同颜色产品或相同价格产品的数量),并且我尝试使用“$group”进行聚合。

result = collection.aggregate(
                            [
                            {
                                "$group" : {"_id":group_aggregation_format, "count": 
                                           {"$sum":1}}
                            }
                            ])
print(result)

group_aggreagtion_format 是这样的数据 {'title': '$title', 'colour': '$colour'}

然后我得到这个错误

| INFO:dill:# T4
web_1            | D2: <dict object at 0x7efec3bfbe40>
web_1            | INFO:dill:D2: <dict object at 0x7efec3bfbe40>
web_1            | T4: <class 'pymongo.client_options.ClientOptions'>
web_1            | INFO:dill:T4: <class 'pymongo.client_options.ClientOptions'>
web_1            | # T4
web_1            | INFO:dill:# T4
web_1            | D2: <dict object at 0x7efec3c13dc0>
web_1            | INFO:dill:D2: <dict object at 0x7efec3c13dc0>
web_1            | T4: <class 'pymongo.common._CaseInsensitiveDictionary'>
web_1            | INFO:dill:T4: <class 'pymongo.common._CaseInsensitiveDictionary'>
web_1            | # T4
web_1            | INFO:dill:# T4
web_1            | D2: <dict object at 0x7efec3b84f00>
web_1            | INFO:dill:D2: <dict object at 0x7efec3b84f00>
web_1            | D2: <dict object at 0x7efec3a79240>
web_1            | INFO:dill:D2: <dict object at 0x7efec3a79240>
web_1            | # D2
web_1            | INFO:dill:# D2
web_1            | D2: <dict object at 0x7efec3bbfc40>
web_1            | INFO:dill:D2: <dict object at 0x7efec3bbfc40>
web_1            | # D2
web_1            | INFO:dill:# D2
web_1            | # D2
web_1            | INFO:dill:# D2
web_1            | T6: <class 'pymongo.auth.MongoCredential'>
web_1            | INFO:dill:T6: <class 'pymongo.auth.MongoCredential'>
web_1            | # T6
web_1            | INFO:dill:# T6
web_1            | T4: <class 'pymongo.auth._Cache'>
web_1            | INFO:dill:T4: <class 'pymongo.auth._Cache'>
web_1            | # T4
web_1            | INFO:dill:# T4
web_1            | D2: <dict object at 0x7efea14a0c80>
web_1            | INFO:dill:D2: <dict object at 0x7efea14a0c80>
web_1            | # D2
web_1            | INFO:dill:# D2
web_1            | T4: <class 'pymongo.pool.PoolOptions'>
web_1            | INFO:dill:T4: <class 'pymongo.pool.PoolOptions'>
web_1            | # T4
web_1            | INFO:dill:# T4
web_1            | D2: <dict object at 0x7efea1524d80>
web_1            | INFO:dill:D2: <dict object at 0x7efea1524d80>
web_1            | cannot pickle 'SSLContext' object

你知道我做错了什么吗? 这是我做聚合的方式吗? 提前致谢!!

这几乎肯定不是您的查询本身; 问题在于您如何创建连接(MongoClient)。

在您执行第一个数据库命令之前,pymongo 不会建立服务器连接,因此即使错误出现在聚合命令上,问题仍然在您的代码的上游。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM