【发布时间】:2017-02-17 19:57:22
【问题描述】:
我是否在其他情况下错误地使用了$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);
}
});
【问题讨论】:
-
您的
firstDayOfMonth值是多少,因为您的Date.now()值是时间戳而不是日期格式? -
@abdul, toISOString?
-
这取决于你,在两种条件下提供相同的格式,它会起作用
-
你能展示你的两个函数的结果吗?
-
2016-10-01T06:28:37.000Z2016-10-10T06:28:37.146Z
标签: javascript node.js mongodb mongoose