Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.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 $elemMatch中的$or语句_Mongodb_Mongodb Query_Nosql - Fatal编程技术网

Mongodb $elemMatch中的$or语句

Mongodb $elemMatch中的$or语句,mongodb,mongodb-query,nosql,Mongodb,Mongodb Query,Nosql,有没有方法在元素匹配中执行$or语句 我有这个: opened: { $elemMatch: { closed: false openingEvening: {$lte: currentTime}, closingEvening: {$gte: currentTime}, } } 并且想把openingMorning添加到l 我如何将其扩展为: opened: { $elemMatch: { closed

有没有方法在元素匹配中执行$or语句

我有这个:

opened: {
    $elemMatch: {
        closed: false
        openingEvening: {$lte: currentTime}, 
        closingEvening: {$gte: currentTime},
    }
}
并且想把openingMorning添加到l

我如何将其扩展为:

opened: {
    $elemMatch: {
        closed: false
        {$or: [
            {openingEvening: {$lte: currentTime}, closingEvening: {$gte: currentTime},},
            {openingMorning: {$lte: currentTime}, closingMorning: {$gte: currentTime}}
         ]
        }
    }
}

这样做可能吗?

当然可以,只是清理了语法,但基本上你做到了:

{
“已打开”:{
“$elemMatch”:{
“关闭”:错误,
“$or”:[
{
“OpeningNight”:{“$lte”:currentTime},
“关闭”:{“$gte”:当前时间}
},
{
“openingMorning”:{“$lte”:currentTime},
“closingMorning”:{“$gte”:currentTime}
}
]
}
}
}
并给出了一个数据示例:

{
“_id”:ObjectId(“537969cee90c3db84958aa86”),
“已打开”:[
{
“关闭”:错误,
“开放之夜”:17,
“关闭”:22,
“开放的早晨”:11,
“closingMorning”:14
}
]
}
{
“_id”:ObjectId(“53796a47e90c3db84958aa87”),
“已打开”:[
{
“关闭”:错误,
“开放的早晨”:13,
“closingMorning”:14
}
]
}
当前时间
12
将与第一个文档匹配,但与第二个文档不匹配,但
13
的值将与这两个文档匹配

还要注意的是,这些都在一个数组中,因此根据您的估计用途,您可能还希望在其中包含一个“dayOfWeek”字段