繁体   English   中英

猫鼬中的 $gte 和 $lte 具有多种条件

[英]$gte and $lte in mongoose with multiple condition

我是否在其他条件下错误地使用了$gte$lte 我得到了空数组,但是当我只做user_email:req.bodu.user_email我就可以获得所有数据。

function firstDayOfMonth() {
  var d = new Date(Date.apply(null, arguments));
  d.setDate(1);
  return d.toISOString();
}

function tomorrowDate() {
  var d = new Date();
  d.setDate(d.getDate() + 1)
  return d.toISOString();
}

Users.find({
    "user_email": req.body.user_email,
    "createdAt": {
      "$gte": firstDayOfMonth(),
      "$lte": tomorrowDate()
    }
  },
  function(err, response) {
    if (!err) {
      console.log(response)
      res.json(response);
    }
  });

它应该工作

我刚刚用这些文档进行了测试

/* 1 */
{
    "_id" : ObjectId("57f9cc3dc4ac279a7c539d0f"),
    "TechActivityId" : 0,
    "LicenseId" : 0,
    "created" : "2016-01-01T00:00:00.000Z",
    "StateofActivity" : "State of Activity",
    "TechGId" : "123121134"
}

/* 2 */
{
    "_id" : ObjectId("57f9e674c4ac279a7c539d10"),
    "TechActivityId" : 0,
    "LicenseId" : 0,
    "created" : "2016-10-10T06:28:37.146Z",
    "StateofActivity" : "State of Activity",
    "TechGId" : "1231234"
}

db.getCollection('hola').find({"created":{"$gte":"2016-01-01T00:00:00.000Z","$lte":"2016-10-10T06:28:37.146Z"}})

我收到了两个文件

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM