'How to include a variable in a Mongoose chain query in Express.js?

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)


Solution 1:[1]

I changed the line for userStored like this:

const userStored = await user
  .find({
    NIC: nUser.NIC
  })
  .where({
    createdAt: {
      '$gte': prevDate
    }
  })

And it worked. Turns out using a comma to add queries was not optimal and also the single commas for the $lte or $gte.

This successfully returned results to the console.

Solution 2:[2]

For anyone looking at this xlibinput_calibrator looks like it requires X11 & was not an option.

I eventually ended up using a startup script to prevent EGT capturing raw events (deleted /dev/event0 or similiar) from the touchscreen & instead use the calibrated source from ts_input.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tyler2P
Solution 2 leo8382