【发布时间】:2014-03-31 10:30:23
【问题描述】:
我们如何使用 $or 和这样的 $where 子句?
此查询应始终返回所有记录(因为日期为 2015 年),但它不返回任何内容。
在部分情况下,它可以工作,但是当尝试将 $or 应用于 Date 或 $where 时,它无法按预期工作。
感谢 Sammaye 将我以前的版本修复为以下(但仍然无法正常工作):
db.turnys.find({
$or:[
{ start:{
$lte:new Date("2015-03-31T09:52:29.338Z")
} },
{ $where:"this.users.length == this.seats" }
]
});
我怎样才能完成预期的 $or?
这里是 turnys 系列的示例:
[
{
"gId": "5335e4a7b8cf51bcd054b423",
"seats": 2,
"start": "2014-03-31T08:47:48.946Z",
"end": "2014-03-31T08:49:48.946Z",
"rMin": 800,
"rMax": 900,
"users": [],
"_id": "53392bb42b70450000a834d8"
},
{
"gId": "5335e4a7b8cf51bcd054b423",
"seats": 2,
"start": "2014-03-31T08:47:48.946Z",
"end": "2014-03-31T08:49:48.946Z",
"rMin": 1000,
"rMax": 1100,
"users": [],
"_id": "53392bb42b70450000a834da"
},
谢谢!
【问题讨论】:
-
展示你的一些文件怎么样?
-
这不是如何格式化 $or 查询,它实际上是一个带有 $and 的 $or 子句
标签: mongodb mongodb-query