0

I am new to mongoose.I am trouble in storing time slots in mongoose db. I have to store time slot for example - 10:00 to 14:00,where startingTime is 10:00 and endTime is 14:00.

So each time when I query the documents in between these time slots of any day.I should get those documents that has these time slots.

I want to make query that do comparison on time slots not on datetime parameter.

I am getting whether I have to store them as string or date ?

Please help.

Udit Kumawat
  • 654
  • 1
  • 8
  • 21
  • 2
    Possible duplicate of [MongoDB/Mongoose querying at a specific date?](http://stackoverflow.com/questions/11973304/mongodb-mongoose-querying-at-a-specific-date) – Douwe de Haan Apr 03 '17 at 11:22

1 Answers1

0

There is no type in Mongo that is a time slot. You need to store two values yourself and compare with them in searches. Far example if you have start and end fields then you may search with:

Model.find({start: {$lte: now}, end: {$gte: now}}, ...);

to find something that is happening now, where now is the current time.

rsp
  • 107,747
  • 29
  • 201
  • 177