Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.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
Arrays 从mongodb gte搜索隐藏子数组不匹配_Arrays_Mongodb_Sub Array - Fatal编程技术网

Arrays 从mongodb gte搜索隐藏子数组不匹配

Arrays 从mongodb gte搜索隐藏子数组不匹配,arrays,mongodb,sub-array,Arrays,Mongodb,Sub Array,因此,我能够让我的gte查询为mongodb工作。但是,我注意到查询whileyes正确地打印出文档。它不会删除/隐藏不正确的子阵列 例如: {history:[{starttime:1593143279079},{starttime:1593236606706}} 现在我只想要gte到1593236606706的子阵列 但是,当我运行以下查询时 {"history.starttime":{$gte:1593236606706}} 我得到了正确的文档,因为是的文档有一个g

因此,我能够让我的
gte
查询为mongodb工作。但是,我注意到查询whileyes正确地打印出文档。它不会删除/隐藏不正确的子阵列

例如:

{history:[{starttime:1593143279079},{starttime:1593236606706}}
现在我只想要gte到1593236606706的子阵列

但是,当我运行以下查询时

{"history.starttime":{$gte:1593236606706}}
我得到了正确的文档,因为是的文档有一个gte,然后是1593236606706,但是我也看到了所有没有相关的子数组,比如1593143279079

现在我知道我可以做foreach签入节点或任何其他程序。但是,在文件返回之前,是否有必要删除或隐藏不相关的文件

下面是示例数据

    {
  "_id": "5ef2bbb25b43e19dab7cac9f",
  "UUID": "72296e08-2086-3b25-b66f-09fe14e7a1b9",
  "ipaddress": "101.118.63.108",
  "history": [
    {
      "HID": "3892b3d0-b5c3-11ea-a984-15a58d42facb",
      "station": "DRN1",
      "starttime": 1592966066060,
      "endtime": 1592966101344
    },
    {
      "HID": "4ccfd300-b5c3-11ea-a984-15a58d42facb",
      "station": "PERTHRadio",
      "starttime": 1592966100016,
      "endtime": 1592966101480
    },
    {
      "HID": "4de53aa0-b5c3-11ea-a984-15a58d42facb",
      "station": "PERTHRadio",
      "starttime": 1592966101833
    },
    {
      "HID": "c4b7af20-b607-11ea-b80a-916b111bece1",
      "station": "PERTHRadio",
      "starttime": 1592995506961,
      "endtime": 1592995508535
    },
    {
      "HID": "c5aa4c80-b607-11ea-b80a-916b111bece1",
      "station": "PERTHRadio",
      "starttime": 1592995508551,
      "endtime": 1592997386659
    },
    {
      "HID": "186f7e40-b68f-11ea-9d92-0ff1a766d952",
      "station": "DRN1",
      "starttime": 1593053629476,
      "endtime": 1593053631582
    },
    {
      "HID": "cb9f79a0-b759-11ea-80ed-dbf0ea8c5f4f",
      "station": "PERTHRadio",
      "starttime": 1593140688441,
      "endtime": 1593141273000
    },
    {
      "HID": "e0c4d920-b75d-11ea-80ed-dbf0ea8c5f4f",
      "station": "PERTHRadio",
      "starttime": 1593142441905
    },
    {
      "HID": "92b648d0-b75e-11ea-a743-2994856ad452",
      "station": "PERTHRadio",
      "starttime": 1593142740444
    },
    {
      "HID": "9db86e20-b75e-11ea-a743-2994856ad452",
      "station": "PERTHRadio",
      "starttime": 1593142758914,
      "endtime": 1593142760449
    },
    {
      "HID": "9ed576e0-b75e-11ea-a743-2994856ad452",
      "station": "PERTHRadio",
      "starttime": 1593142760781
    },
    {
      "HID": "d670b1a0-b75e-11ea-a29a-c19990a8e870",
      "station": "PERTHRadio",
      "starttime": 1593142854073
    },
    {
      "HID": "d74e1950-b75e-11ea-a29a-c19990a8e870",
      "station": "PERTHRadio",
      "starttime": 1593142855525,
      "endtime": 1593142860214
    },
    {
      "HID": "d948b0d0-b75e-11ea-a29a-c19990a8e870",
      "station": "PERTHRadio",
      "starttime": 1593142858845,
      "endtime": 1593142860481
    },
    {
      "HID": "da540650-b75e-11ea-a29a-c19990a8e870",
      "station": "PERTHRadio",
      "starttime": 1593142860597
    },
    {
      "HID": "e8f683e0-b75e-11ea-a56b-635bc76b120b",
      "station": "PERTHRadio",
      "starttime": 1593142885149
    },
    {
      "HID": "3bc788d0-b75f-11ea-aab1-4d8374b59f5f",
      "station": "PERTHRadio",
      "starttime": 1593143024093
    },
    {
      "HID": "5b69add0-b75f-11ea-8e0e-9de052ed5763",
      "station": "PERTHRadio",
      "starttime": 1593143077164
    },
    {
      "HID": "79db9030-b75f-11ea-b9e5-6780a994ba91",
      "station": "PERTHRadio",
      "starttime": 1593143128243
    },
    {
      "HID": "8f4f0c80-b75f-11ea-9c42-15965300ded2",
      "station": "PERTHRadio",
      "starttime": 1593143164231
    },
    {
      "HID": "b6cfcfb0-b75f-11ea-893e-33873840b421",
      "station": "PERTHRadio",
      "starttime": 1593143230506
    },
    {
      "HID": "d3c37680-b75f-11ea-9e35-8b493642ae94",
      "station": "PERTHRadio",
      "starttime": 1593143279079
    },
    {
      "HID": "e9722710-b75f-11ea-9962-75b52c48511f",
      "station": "PERTHRadio",
      "starttime": 1593143315456
    },
    {
      "HID": "1a92c070-b760-11ea-a959-a184cc7e1bde",
      "station": "PERTHRadio",
      "starttime": 1593143397878
    },
    {
      "HID": "3146d310-b760-11ea-8069-d9d0a9c80a89",
      "station": "PERTHRadio",
      "starttime": 1593143435968
    },
    {
      "HID": "569b4060-b760-11ea-8fb3-57fc4edb6600",
      "station": "PERTHRadio",
      "starttime": 1593143498598
    },
    {
      "HID": "6d8b0960-b795-11ea-9545-fb36a6e7214b",
      "station": "DRN1",
      "starttime": 1593166300405,
      "endtime": 1593166301643
    },
    {
      "HID": "1f5d3430-b839-11ea-a52e-81ad305f80cc",
      "station": "DRN1",
      "starttime": 1593236606706,
      "endtime": 1593236607927
    }
  ]
}

您需要筛选数组

{
    $project:{
        "history":{
            $filter:{
                input:"$history",
                cond:
                    {$gte:["$$this.starttime",1593236606706]}               
            }
        }
    }
}

工作

您可以使用位置投影运算符$仅检索匹配的数组元素。请提供一个示例@文档中有一些例子。我试过你的代码,它给了我这个错误
必须是一个像“[{id:1},{{id:2}]”这样的文档数组。
我已经添加了我们的示例数据,但我还要看看是否可以对您的代码进行一些修改以使其正常工作。我可以理解您的答案的意思。我根据您提供的内容给出了答案,并且工作正常。最好修改问题以更新数据结构。我已经更新了问题。对不起,我以为我说得够清楚了。我的错。很抱歉,我的浏览器没有发布更新-现在我没有收到任何错误,您提供的数据