I am new to the mongoose and Express and I am stuck with querying in Mongoose.
I need to get the users by filtering their NIC (key) and createdAt fields with greater than and less than keywords and for createdAt I need to compare it to a variable. The code is as follows.
const setData = asyncHandler(async (req, res) => {
const prevDate = new Date(Date.now() - 1000 * 86400).toISOString();
const nUser = new user({
Name: req.body.name,
Age: req.body.age,
NIC: req.body.NIC,
Sex: req.body.sex,
Telephone: req.body.tel,
Address: req.body.addr,
email: req.body.email,
Inquiry: req.body.inquiry,
Branch:req.body.branch,
askLoan:req.body.askLoan
})
// await nUser.save();
// console.log (nUser)
const userStored = await user.find({ NIC: nUser.NIC},**{createdAt: {$lte: prevDate}})**
console.log(userStored)