MongoDb $gte and $lte on date issue

Viewed 459
{
  "employeeID": ObjectId("5e8f5beaa3164b5ac87a74de"),
  "startDate": { 
    '$gte':new Date("Wed, 20 May 2020 07:00:00 GMT")
  },
  "endDate": { 
    '$lte':new Date("Wed, 20 May 2020 07:00:00 GMT")
  }
}

Sample Document :

employeeID:5e8f5beaa3164b5ac87a74de 
employeeCode:"TX3215" 
firstName:"Kiruthika" 
lastName:"Venkatachalam" 
employeeEmailId:"kvenkatachalam@technicax.com" 
companyID:5e8f5be7a3164b5ac87a74dd
companyCode:"TCAX0213" 
companyName:"Technicax" 
approverName:"Dev K Subram" 
leaveCode:"Vacation" 
startDate:2020-05-19T07:00:00.000+00:00 
endDate:2020-05-22T07:00:00.000+00:00
approvalStatus:"Submitted" 
submittedDate:"2020-05-22T00:04:25.815Z" 
approvedDate:"" 
comments:"Vacation" 
hours:8 
isActive:true
availableForContact:false 
emergencyContactName:null 
emergencyContactNumber:null
county:"" timeZone:""

Trying to find if there are any records available for the given date. Doesn't fetch the record which matches the condition. Eg, I have a record created with a start date as Jun 1, 2020 & end date as Jun 5, 2020. I try to query if there is any record for Jun 3, 2020 with the above query, Start date, and end Date is of type Dates.

startDate: { type: Date },
endDate: { type: Date },

Scenario: An employee can raise a vacation fro June 1 2020 to June 5, 2020. When the same person tries to create another record for June 3, 2020. I am trying to check if there is a record with a start date greater than the current date and end date less than the current Date to validate if there is a record for the date.

0 Answers
Related