2

I have saved my date as timestamp, using the below logic:

var timestamp = Math.floor(new Date().getTime()/1000);
timestamp =145161061

Can any one help me out with the query?

I need to find records between dates and my date is stored in timestamp format as shown above.

2 Answers 2

6

If you have specified the type of the field to be date, then even if you store the date by giving the time stamp, it will get stored as Date.

To do a range query on date you can simply do something like this:

db.events.find({"event_date": {
$gte: ISODate("2010-01-01T00:00:00Z"),
$lt: ISODate("2014-01-01T00:00:00Z"),}})

But then if you have specified it as Number, then you can simply do a range query on the number like this :

db.events.find({"event_date": {
$gte: 145161061,
$lt: 145178095,}})
Sign up to request clarification or add additional context in comments.

Comments

0

You can try kind of this query:

var startTime = 145161061;
var endTime = 149161061;
Books.find({
    created_at: {
        $gt: startTime,
        $lt: endTime
    } 
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.