Pymongo与$ exists = true给出错误。 “无法识别的表达'$存在'”

时间:2017-02-01 21:07:58

标签: python mongodb pymongo

db.VibrationData.aggregate([{
    "$unwind": "$Records"
}, {
    "$redact": {
        "$cond": [{
                "$anyElementTrue": {
                    "$map": {
                        "input": "$Records.Properties",
                        "as": "result",
                        "in": {
                            "$and": [{
                                "$eq": ["$$result.Property.Name", "LastWrite_User"]
                            }, {
                                "$eq": ["$$result.value", "42"]
                            }]
                        }
                    }
                }
            },
            "$$KEEP",
            "$$PRUNE"
        ]
    }
}, {
    "$unwind": "$Records.Properties"
}, {
    "$match": {
        "Records.Properties.Property.Name": 'LastWrite_Time'
    }
}, {
    "$project": {
        "_id": 0,
        "value": "$Records.Properties.value"
    }
}])

现在我试图做同样的事情,除了使用$ exists函数

LastWrite_Time = coll.aggregate([{
    "$unwind": "$Records"
}, {
    "$redact": {
        "$cond": [{
                "$anyElementTrue": {
                    "$map": {
                        "input": "$Records.Properties",
                        "as": "result",
                        "in": {
                            "$and": [{
                                "$eq": ["$$result.Property.Name", "LastWrite_Time"]
                            }, {
                                "$eq": ["$$result.value", {'$exists': True}]
                            }]
                        }
                    }
                }
            },
            "$$KEEP",
            "$$PRUNE"
        ]
    }
}, {
    "$unwind": "$Records.Properties"
}, {
    "$match": {
        "Records.Properties.Property.Name": 'LastWrite_Time'
    }
}, {
    "$project": {
        "_id": 0,
        "value": "$Records.Properties.value"
    }
}])

但是我得到了这个错误

Traceback (most recent call last):
  File "C:\Python_scripts\SimulationCEI.py", line 58, in <module>
    "value": "$Records.Properties.value"
  File "C:\Python27\lib\site-packages\pymongo\collection.py", line 1870, in aggregate
    collation=collation)
  File "C:\Python27\lib\site-packages\pymongo\collection.py", line 232, in _command
    collation=collation)
  File "C:\Python27\lib\site-packages\pymongo\pool.py", line 419, in command
    collation=collation)
  File "C:\Python27\lib\site-packages\pymongo\network.py", line 116, in command
    parse_write_concern_error=parse_write_concern_error)
  File "C:\Python27\lib\site-packages\pymongo\helpers.py", line 210, in _check_command_response
    raise OperationFailure(msg % errmsg, code, response)
OperationFailure: Unrecognized expression '$exists'

我看了一眼 mongodb $exists always returning 0

它似乎应该有用......任何想法

0 个答案:

没有答案