使用$和条件的Mongoose $或查询条件

时间:2012-11-17 18:31:06

标签: mongoose

我正试图让这个简单的查询与Mongoose一起工作,没有运气:明天在会议中心发现所有发生的事件。对于每个事件,计划可以是特定的开始时间作为日期类型,也可以是字符串格式为“2012/11/16”的日期数组。相同的query.or条件但是当{place:'conference center'}没有条件时,所以我认为我可能错误地编写了这个查询。到目前为止我没有运气,建议/帮助吗? “明天”条件是添加到“地点”条件的过滤器,因此我使用查询链接。

谢谢!

    Event.find({place:'conference center'}).or([
      { 
        'schedule.beginAtUtc' : { $gte: startOfTomorrow },
        'schedule.beginAtUtc' : { $lt: endOfTomorrow }
      },

      {
        'schedule.dates' : '2012/11/17'
      }
    ]);

1 个答案:

答案 0 :(得分:4)

您必须将两个'schedule.beginAtUtc'字段合并为一个,因为对象不能有两个具有相同名称的字段。

像这样:

Event.find({place:'conference center'}).or([
  { 
    'schedule.beginAtUtc' : { $gte: startOfTomorrow, $lt: endOfTomorrow }
  },

  {
    'schedule.dates' : '2012/11/17'
  }
]);
相关问题