Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/400.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
Javascript 如何使用mongoose查询嵌套对象中的对象数组?_Javascript_Node.js_Mongodb_Express_Mongoose - Fatal编程技术网

Javascript 如何使用mongoose查询嵌套对象中的对象数组?

Javascript 如何使用mongoose查询嵌套对象中的对象数组?,javascript,node.js,mongodb,express,mongoose,Javascript,Node.js,Mongodb,Express,Mongoose,我想查询包含状态就绪的所有对象 在数据对象键foo、bar、abc中可以是任何东西。这里不知道钥匙的名字 我希望所有的数据对象至少有一个键值对的状态就绪 预期结果: dbCollection= [ { _id: "2632831628319231", text: 'xyz', data: { foo: [ { message:"Hello",statu

我想查询包含状态就绪的所有对象

在数据对象键foo、bar、abc中可以是任何东西。这里不知道钥匙的名字

我希望所有的数据对象至少有一个键值对的状态就绪

预期结果:

dbCollection= [
      {
        _id: "2632831628319231",
        text: 'xyz',
        data: {
          foo: [
            {  message:"Hello",status: 'notready' },
            { message:"Hello", status: 'notready' },
          ],
          bar: [
            { message:"Hello", status: 'ready' },
            { message:"Hello", status: 'notready' },
          ],
          foo1: [
            { message:"Hello", status: 'ready' },
            { message:"Hello", status: 'notready' },
          ],  
        },
      },
      {
        _id: "2632831628319231",
        text: 'stu',
        data: {
          abc: [
            {  message:"Hello",status: 'notready' },
            { message:"Hello", status: 'notready' },
          ],
          ghi: [
            { message:"Hello", status: 'ready' },
            { message:"Hello", status: 'notready' },
          ],
        },
      },
    ];
所以我想通过使用mongoose aggregate或find来获得这个结果,但我没有通过mongoose找到解决这个问题的适当方法,只是目前我正在查询数据并使用一些javascript方法来解决这个问题

[{
        _id: "2632831628319231",
        text: 'xyz',
        data: {
          bar: [
            { message:"Hello", status: 'ready' },
            { message:"Hello", status: 'notready' },
          ],
          foo1: [
            { message:"Hello", status: 'ready' },
            { message:"Hello", status: 'notready' },
          ],
        },
      },{
        _id: "2632831628319231",
        text: 'stu',
        data: {
          ghi: [
            { message:"Hello", status: 'ready' },
            { message:"Hello", status: 'notready' },
          ],
        },
      },]