Node.js 使用nodeJS从mongoDB查询一整天的数据时出现问题
我需要一些帮助来了解Date如何与MongoDB一起工作。所以在MongoDB中,我想检索今天日期的集合,例如,从今天上午12:00到今晚晚上11:59。 这是我在nodeJS中的查询Node.js 使用nodeJS从mongoDB查询一整天的数据时出现问题,node.js,angular,mongodb,express,Node.js,Angular,Mongodb,Express,我需要一些帮助来了解Date如何与MongoDB一起工作。所以在MongoDB中,我想检索今天日期的集合,例如,从今天上午12:00到今晚晚上11:59。 这是我在nodeJS中的查询 const router = express.Router(); router.get("/today", checkAuth, (req, res, next) => { today = new Date(); daysLeftInMonth = new Date(ne
const router = express.Router();
router.get("/today", checkAuth, (req, res, next) => {
today = new Date();
daysLeftInMonth =
new Date(new Date().getFullYear(), new Date().getMonth() + 1, 0).getDate() -
today.getDate();
gtDate = new Date(
today.getFullYear().toString() +
"-" +
(today.getMonth() + 1).toString() +
"-" +
today.getDate()
);
ltDate = new Date(
today.getFullYear().toString() +
"-" +
(today.getMonth() + 1).toString() +
"-" +
today.getDate()
);
ltDate.setHours(23);
ltDate.setMinutes(59);
ltDate.setSeconds(59);
const saleQuery = Sale.find({
creator: req.userData.userId,
date: {
$gt: gtDate,
$lt: ltDate,
},
});
let fetchedSales;
saleQuery
.then((documents) => {
fetchedSales = documents;
return Sale.countDocuments();
})
.then((count) => {
res.status(200).json({
message: "Sales fetched successfully!",
sales: fetchedSales,
});
});
});
当我在localhost中运行时,这很好用。
但当我把我的制作文件上传到beanstalk时,它只会在下午5点之前检索收藏。
感谢您的帮助。先谢谢你
角度CLI:10.1.7
节点:12.19.0
操作系统:win32 x64我想冒昧地猜测一下,您在山区时间(UTC-7),豆茎默认为UTC。我不知道。太好了,谢谢@乔