0

This doesn't work

FindIterable<Document> result = db.getCollection(resourceName)
                                          .find(Filters.eq("time", "1262599860000"))
                                          .batchSize(batchSize)
                                          .skip(offset);

But the field is NumberLong, so it should ? And the below does work :

FindIterable<Document> result = db.getCollection(resourceName)
                                          .find(Filters.gt("time", 100))
                                          .batchSize(batchSize)
                                          .skip(offset);

How do I correctly specify a long value to a MongoDb filter via java ? The mongo shell shows :

db.events.find({time:1262599860000})
{ "_id" : "507f191e810c19729de8aae3", "type" : "LOGIN", "time" : NumberLong("1262599860000"), "user" : "[email protected]", "ip" : "192.168.1.13" }
5
  • @NeilLunn they are not duplicates ? Neither use Filter ? Commented Sep 22, 2019 at 6:30
  • The driver will be happy with any method to instantiate a Long and treat it as NumberLong when converting to BSON. Neither your string or default numeric value are a Long. So cast as one. BTW batchSize() is not a limit() as you appear to be assuming by using in combination with skip(). That's just a method for setting the number of results returned in the "cursor fetch" ( a low level internal thing ) as a "get more" operation. But it does not limit the number of results returned. Commented Sep 22, 2019 at 6:30
  • you can't pass long to Filters.eq ? Commented Sep 22, 2019 at 6:31
  • Yes you can. Many people have done this many times before. Commented Sep 22, 2019 at 6:31
  • Presumably of a FindIterable based on the syntax above. At any rate the correct method should be limit() in ALL implementations. Just as batchSize() does the same thing in ALL implementations. Which is again, not what you seem to want here. Commented Sep 22, 2019 at 6:36

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.