【问题标题】:Mongodb aggregation in Python : cannot pickle 'SSLContext' objectPython中的Mongodb聚合:无法腌制'SSLContext'对象
【发布时间】:2021-10-22 02:11:36
【问题描述】:

我需要找到相同组的数量(例如相同颜色产品或相同价格产品的数量),我尝试使用“$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

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

【问题讨论】:

    标签: python django mongodb aggregation-framework pymongo


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2020-09-10
      • 2020-04-07
      • 2021-01-27
      • 2023-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多