Kunok
Kunok

Reputation: 8759

Mongo find all objects that are created within specific hours when using systematic time format

I have objects in Mongo database with values such as: 1477663239000.

In JavaScript I can convert it to date:

new Date(1477663239000)
// => Date 2016-10-28T14:00:39.000Z

Is it possible to query mongodb to get all objects that are matching time from around 5 PM and 8 PM in July for example?

Upvotes: 0

Views: 39

Answers (1)

Noah Wallace
Noah Wallace

Reputation: 118

You won't need to convert it to a date string in order to query a series of dates. Mongo dB will accept a number/time as a valid date.

{Date:{"$gte":12345,"$lte":12355}}

Behavior

Internally, Date objects are stored as a 64 bit integer representing the number of milliseconds since the Unix epoch (Jan 1, 1970), which results in a representable date range of about 290 millions years into the past and future.

// from mongo documentation

Upvotes: 1

Related Questions