Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python MongoDB:如何确定特定值是否不存在_Python_Mongodb - Fatal编程技术网

Python MongoDB:如何确定特定值是否不存在

Python MongoDB:如何确定特定值是否不存在,python,mongodb,Python,Mongodb,我只能找到一些例子来确定特定的键是否不存在 我的MongoDB实例中有特定的文档,这些文档包含如下字段: "actions" : [ { "date" : "2015-03-09T15:28:03Z", "reason" : "", "begin_date" : "2015-03-09T15:28:03Z",

我只能找到一些例子来确定特定的键是否不存在

我的MongoDB实例中有特定的文档,这些文档包含如下字段:

        "actions" : [
            {
                    "date" : "2015-03-09T15:28:03Z",
                    "reason" : "",
                    "begin_date" : "2015-03-09T15:28:03Z",
                    "end_date" : "2015-03-09T15:28:03Z",
                    "action_type" : "Block",
                    "performed_date" : "2015-03-09T15:28:03Z",
                    "active" : "on",
            },
            {
                    "date" : "2015-03-09T15:28:03Z",
                    "reason" : "",
                    "begin_date" : "2015-03-09T15:28:03Z",
                    "end_date" : "2015-03-09T15:28:03Z",
                    "action_type" : "Alert",
                    "performed_date" : "2015-03-09T15:28:03Z",
                    "active" : "on",
            },
            {
                    "date" : "2015-03-09T15:28:03Z",
                    "reason" : "None",
                    "begin_date" : "2015-03-09T15:28:03Z",
                    "end_date" : "2015-03-09T15:28:03Z",
                    "action_type" : "History",
                    "performed_date" : "2015-03-09T15:28:03Z",
                    "active" : "on",
            }
    ],
现在,我正在尝试生成一个查询,以返回“action_type”:“History”不存在的所有记录

我知道$exists操作符可以告诉我“action\u type”键是否不存在,但我找不到任何示例来告诉我在哪里可以指定哪些值不存在

在我的脑海中,我想说是这样的(但显然这不起作用):


希望这比我所说的要容易得多。

您实际上是想检查一个值是否不是什么东西吗?i、 e.密钥将始终存在,但您希望在值不是“历史”的情况下进行匹配

如果是这样的话,就有Not Equals操作符:

这应该起作用:

db.collection.find({"actions.action_type": {"$ne": "History"}})

是的,正如我所预料的,比我想象的要容易得多。非常好用,谢谢@gleb1783我不认为这给出了您期望的结果,上面的查询没有显示任何结果。是的,您得到了。皮埃尔打了你一顿,我接受了他的回答:“诅咒你,皮埃尔!”D
db.collection.find({"actions.action_type": {"$ne": "History"}})