【发布时间】: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