Tolledo
Tolledo

Reputation: 609

Issue with creating a query in mongodb with NumberLong

I've got a class in my Java application with field

Instant created;

This one is stored in mongo as

"created" : NumberLong("1467359610266") (f.e.)

I want to create a query to get all the documents, that was created beetween 2 dates:

    public List<MarketingEmail> find(Long startDate, Long endDate) {
    Query query = new Query();
    query.addCriteria(Criteria.where("created").gte(startDate).lte(endDate));
    ...
}

I pass the timestamp variables startDate and endDate (f.e. endDate = 1467981757). So the issues is that NumberLong in MongoDB has 13 digits, when my timestamp has ony 10; so my query doesn't work at all

How can i solve this issue?

Upvotes: 2

Views: 588

Answers (1)

profesor79
profesor79

Reputation: 9473

Mongo timestamp uses milliseconds.

To query it multiply your value by 1000 (or simple add 000 at the end)

Upvotes: 2

Related Questions