Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.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
Mongodb 查找存在一个或多个嵌套键的所有文档_Mongodb - Fatal编程技术网

Mongodb 查找存在一个或多个嵌套键的所有文档

Mongodb 查找存在一个或多个嵌套键的所有文档,mongodb,Mongodb,我试图找出如何为存在一个或多个嵌套键的所有文档设置键。因此,以下面的集合为例 [ {u id=“设置1” ,name=“setting1Name” ,description=“这是说明” ,values={us=“good” ,uk=“很棒” 因此,我想找到在['us','lu'中的值中包含键的文档。我知道如何做到这一点 query=mongo.collection(“settings”).find({“values.us”={“$exists”=“true”}}) 但如果“我们”或“鲁”存在,

我试图找出如何为存在一个或多个嵌套键的所有文档设置键。因此,以下面的集合为例

[ {u id=“设置1” ,name=“setting1Name” ,description=“这是说明” ,values={us=“good” ,uk=“很棒”

因此,我想找到在['us','lu'中的值中包含键的文档。我知道如何做到这一点

query=mongo.collection(“settings”).find({“values.us”={“$exists”=“true”}})

但如果“我们”或“鲁”存在,那么最好的扩展方式是什么


谢谢

尝试使用“$or”操作符。我已经习惯了php语法,但你会明白的

$where = array(
    '$or' => array(
        array('values.us' => array('$exists' => TRUE)),
        array('values.lu' => array('$exists' => TRUE))
    )
);

$query = $collection->find($where);

尝试使用“$or”操作符。我已经习惯了php语法,但你会明白的

$where = array(
    '$or' => array(
        array('values.us' => array('$exists' => TRUE)),
        array('values.lu' => array('$exists' => TRUE))
    )
);

$query = $collection->find($where);