Mongodb Pymongo:聚合没有一个字段但有另一个字段的所有文档-分组依据
我正在尝试从我的收藏中获取一组文档,条件如下: 字段:img_状态不存在 字段:图像应该存在 然后,将这些文档按一个字段进行分组(唯一/不同)。 当我在MongoDB中执行查询时,它似乎返回了正确的值:Mongodb Pymongo:聚合没有一个字段但有另一个字段的所有文档-分组依据,mongodb,aggregation-framework,pymongo,Mongodb,Aggregation Framework,Pymongo,我正在尝试从我的收藏中获取一组文档,条件如下: 字段:img_状态不存在 字段:图像应该存在 然后,将这些文档按一个字段进行分组(唯一/不同)。 当我在MongoDB中执行查询时,它似乎返回了正确的值: db.getCollection('products').aggregate([ { $match: { images: { $exists: true, $ne: null } } }, { $match: { img_status: { $exists: false } } }, { $gr
db.getCollection('products').aggregate([
{ $match: { images: { $exists: true, $ne: null } } },
{ $match: { img_status: { $exists: false } } },
{ $group : { _id:"$vendor_link", "uuid" : {$first: "$uuid"}, "images": { $first: "$images"} } }
])
但在PyMongo,我总是得到相反的结果,比如:img_status exist=true:
我做错了什么?这应该可以解决问题。您传递的是字符串值,而不是None和布尔值True和False 管道=[ { $match:{ 图像:{ $ne:没有, $exists:True, } } }, { $match:{ img_状态:{ $exists:False, } } }, { $group:{ _id:$vendor\u link, 图像:{$first:$images}, uuid:{$first:$uuid}, 来源:{$first:$source} } }, ] pprintlistself.collection.AggregatePiline
pipeline = [
{
"$match":
{
"images" :
{ "$ne" : "null", "$exists": "true", }
}
},
{
"$match":
{
"img_status":
{"$exists": "false"}
}
},
{
"$group":
{
"_id" : "$vendor_link",
"images" : {"$first": "$images"},
"uuid" : {"$first": "$uuid"},
"source" : {"$first": "$source"}
}},
]
pprint(list(self.collection.aggregate(pipeline)))