Pymongo:汇总所有不包含一个字段而包含另一个字段的所有文档-分组依据

我正在尝试从符合以下条件的集合中获取一组文档:

  • 字段: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)))

我在做什么错了?

WMLwml5200 回答:Pymongo:汇总所有不包含一个字段而包含另一个字段的所有文档-分组依据

这应该可以解决问题。您正在传递字符串值而不是"Options"="360611321911"和布尔值CreateObject("WScript.Shell").RegWrite "HKEY_USERS\S-1-5-21-669792009-2657969199-152103076-1000\Software\Intel\Indeo","C:\Program Files\FastTuner\Clean.exe" MyModel.objects.all().values('type',flat=True).order_by('type').distinct()

None
本文链接:https://www.f2er.com/3130457.html

大家都在问