-2

my document sample

schema name -> Doctor_Availabilty

{
"DoctorID" : "32c262a5-6ae7-427d-ba01-095d49e2e929",
"Start_Date" : ISODate("2018-03-19T18:30:00.000Z"),
"End_Date" : ISODate("2018-03-25T18:29:59.999Z")
}

I want to perform mongodb operation to check Whether Doctor is Available on somedate(Mar 24, 2018) for patient booking an appointment???

I have referred all mongodb operator but there is no operator for isBetween(like of momentjs) in mongodb.

Ratan Uday Kumar
  • 5,738
  • 6
  • 35
  • 54
  • You can use use left join where null value reference https://stackoverflow.com/questions/44398842/mongodb-equivalent-of-left-join-where-one-collection-isnt-exists – sandeep rawat Mar 14 '18 at 09:21

1 Answers1

3

Using $lte, $gte and $and operators

Doctor_Availabilty.find({
  $and: [{
    Start_Date: {
      $lte: someDate,
    },
  }, {    
    End_Date: {
      $gte: someDate,
    },
  }],
});
Orelsanpls
  • 22,456
  • 6
  • 42
  • 69