Hi I have a mongodb database with employee collection. The documents inside collection look like this -
{
"_id": {
"$oid": "5fac29ace10c301364931902"
},
"id": 11,
"first_name": "Kristi",
"last_name": "Dorkins",
"email": "kdorkinsa@livejournal.com",
"gender": "Female",
"startDate": "07/04/2012",
"endDate": "30/03/2019",
"deviceStatus": true
}
I need the employees whose 'startDate' is greater than a specific date(which I'm passing to server from frontend). The Date format I pass to the server looks like this-
2020-11-14T10:36:21.053Z
Since the date in database is in a string format("11/05/2011") I can't find a way to convert that to actual date object in the query statement.
let temp = new Date(req.query.startDate);
dbase.collection("employee").find({new Date(startDate): { $gte: new Date(temp) }})
.toArray()
.then((res) => console.log(res));
In the above query I tried creating a date object of the key('startDate') but that's not possible it seems.
When I tried in a different way like this just to test-
dbase.collection("employee").find({startDate: { $gte: "02/11/2010" }})
.toArray()
.then((result) => {
console.log(result.length);
res.send(result);
});
For the above query I'm getting all documents with first two digits of startDate greater than first two digits of the given date(greater than '2' in above case). That is not working either
I have already gone through this thread return query based on date and different other similar questions, but they all have the date key stored in database in an ISO or a different format. Also since I'm new to MongoDB and I tried all possible ways which I know. Kindly help