Javascript 如何执行使用AND和OR的条件Mongoose查询?

Javascript 如何执行使用AND和OR的条件Mongoose查询?,javascript,node.js,mongodb,mongoose,database,Javascript,Node.js,Mongodb,Mongoose,Database,我想用猫鼬做一个复杂的and/or查询。下面是一些伪代码,显示了我正在尝试做的事情: Find persons where ( (date_begin == null || date_begin <= today) && (date_end == null || date_end >= tomorrow) ) 如有任何建议,将不胜感激!(仅供参考,今天和明天都很好,这是我要问的猫鼬语法。)动态化 通过像这样直接使用mongodb,您可以执行以下操作: P

我想用猫鼬做一个复杂的and/or查询。下面是一些伪代码,显示了我正在尝试做的事情:

Find persons where (
  (date_begin == null || date_begin <= today)
  && (date_end == null || date_end >= tomorrow)
)
如有任何建议,将不胜感激!(仅供参考,今天和明天都很好,这是我要问的猫鼬语法。)

动态化

通过像这样直接使用mongodb,您可以执行以下操作:

  Person.find({
      $and: [
          { $or: [{date_begin: null}, {date_begin: {$lte : today}}] },
          { $or: [{date_end: null}, {date_end: {$gte : tommorow}}] }
      ]
  }, function (err, results) {
      ...
  }

这很有效,非常感谢!
  Person.find({
      $and: [
          { $or: [{date_begin: null}, {date_begin: {$lte : today}}] },
          { $or: [{date_end: null}, {date_end: {$gte : tommorow}}] }
      ]
  }, function (err, results) {
      ...
  }