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" : "user4@sample.io", "ip" : "192.168.1.13" }
NimChimpsky
  • 46,453
  • 60
  • 198
  • 311
  • @NeilLunn they are not duplicates ? Neither use Filter ? – NimChimpsky Sep 22 '19 at 06: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. – Neil Lunn Sep 22 '19 at 06:30
  • you can't pass long to Filters.eq ? – NimChimpsky Sep 22 '19 at 06:31
  • Yes you can. Many people have done this many times before. – Neil Lunn Sep 22 '19 at 06:31
  • Presumably of a [`FindIterable`](http://mongodb.github.io/mongo-java-driver/3.6/javadoc/com/mongodb/client/FindIterable.html#limit-int-) 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. – Neil Lunn Sep 22 '19 at 06:36

0 Answers0