app.get("/expenses/:month", async (req, res) => {
const { month } = req.params;
const regexp = new RegExp("\d\d\d\d-" + month + "-\d\d");
console.log(regexp);
const allExpenses = await Expense.find({ date: { $regex: regexp } });
const allEarnings = await Earning.find({ date: { $regex: regexp } });
console.log(allExpenses);
res.status(200).json({
status: "success",
results: allExpenses.length,
data: {
allExpenses,
allEarnings
}
});
你好,我正在尝试使用regexp过滤出特定月份的数据。它查找没有regexp的数据,但是一旦我把它放进去,它就返回一个空数组。
1条答案
按热度按时间rekjcdws1#
我认为问题可能是你没有逃避反斜杠