2

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?

1 Answer 1

2

Mongo timestamp uses milliseconds.

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

Sign up to request clarification or add additional context in comments.

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.