There are 4 records in my database.
{"_id":{"$oid":"6200b15e91f762376cd43ac3"},"startDate":{"$date":"2021-01-01T00:00:00.000Z"},"endDate":{"$date":"2021-01-28T18:29:59.059Z"},"__v":0}
{"_id":{"$oid":"6200b15e91f762376cd43ac4"},"startDate":{"$date":"2021-01-01T00:00:00.000Z"},"endDate":{"$date":"2021-01-23T18:29:59.059Z"},"__v":0}
{"_id":{"$oid":"6200b15e91f762376cd43ac5"},"startDate":{"$date":"2021-01-05T00:00:00.000Z"},"endDate":{"$date":"2021-01-28T18:29:59.059Z"},"__v":0}
{"_id":{"$oid":"6200b15e91f762376cd43ac6"},"startDate":{"$date":"2021-01-05T00:00:00.000Z"},"endDate":{"$date":"2021-01-25T18:29:59.059Z"},"__v":0}
My UI looks like this:
My mongodb query is as follows: (what I have tried)
data.find({
"$or": [
{"startDate": {"$gte": startDate}},
{"endDate": {"$lte": endDate}}
]
});
When is search using the query above, I get only 1 record, That is: {"_id":{"$oid":"6200b15e91f762376cd43ac3"},"startDate":{"$date":"2021-01-01T00:00:00.000Z"},"endDate":{"$date":"2021-01-28T18:29:59.059Z"},"__v":0} instead of all 4.
While sending from UI, I convert it is: req.query:
dateStart: '2021-01-01',
dateEnd: '2021-01-28',
And then convert it to new Date() format:
let startDate = new Date(req.query.dateStart);
let endDate = new Date(req.query.dateEnd);
I don't know what wrong I am going in the query. Need Help! Thank you!
Via Active questions tagged javascript - Stack Overflow https://ift.tt/dWYMstC
Comments
Post a Comment