0

Using Jongo API to query MongoDB, I can fetch documents from last 5 days with

Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
employees.find(
  "{ createdOn: { $gt:  # } }", 
  cal.getTimeInMillis() - 5 * 24 * 60 * 60 * 1000
); 

I would like to know how to query records in time interval (5 days from now, 3 days from now).

Assuming today is Aug 9, I need records from 4th to 6th Aug.

Thanks.

mr.tarsa
  • 6,386
  • 3
  • 25
  • 42
Kathire
  • 53
  • 1
  • 8

1 Answers1

1

According to documentation, with Jongo API you can pass multiple parameters to your query as

employees.find(
  "{ createdOn: { $gt: #, $lt: #  } }",
  nowInMs - 5 * 24 * 60 * 60 * 1000, 
  nowInMs - 3 * 24 * 60 * 60 * 1000
);

that will find documents with createdOn field in time interval (5 days from now; 3 days from now).

mr.tarsa
  • 6,386
  • 3
  • 25
  • 42