batchSize(int) limiting number of return objects rather than in memory objects
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)