我正在尝试从符合以下条件的集合中获取一组文档:
- 字段:img_status不存在
- 字段:图像应该存在
然后,将这些文档(唯一/不同)按一个字段分组。 当我在MongoDB中执行查询时,好像它返回了正确的值:
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
:
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)))
我在做什么错了?