morphia icon indicating copy to clipboard operation
morphia copied to clipboard

batchSize(int) limiting number of return objects rather than in memory objects

Open miosman opened this issue 13 years ago • 0 comments

I have to make a pass on all the data in a large collection, fetching all the data directly with .asList() is very memory inefficient. I read an answer on the original morphia user group https://groups.google.com/forum/?fromgroups=#!topic/morphia/RIBvEBX_g3M that advises to use ds.find().

However, without setting batchSize(int) for a large result set the jvm is likely to crash due to the default behaviour of the mongo driver to keep all the data in memory.

The issue is if I do set batchSize(int) and use ds.find() morphia will only return the number set in batchSize(int) not the whole collection doing a new fetch from the server everytime you pass that size. I can get the correct behaviour using the default mongo driver. So I am not sure is it a bug in morphia or by design.

This a sample query that I do: _dao.getDatastore().find(Post.class).field("timestamp").greaterThanOrEq(timestamp).order("timestamp").disableCursorTimeout().batchSize(100)

miosman avatar Mar 17 '13 15:03 miosman