Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

196
Views
morphia mongodb retreive huge data batchwise

I want to retrieve 200 000 data from db from mongodb using morphia.

Earlier I was using

query.asList()

which gave me out of memory exception I tried changing it to

query.batchSize(50).asList()

but with no luck.

I update my code to

Iterable<DataStreams> iterable= query.fetch();
            Iterator<DataStreams> iterator=iterable.iterator();
            while (iterator.hasNext()) {
               dataStreamsList.add(iterator.next());                
            }           
           System.out.println("iteration done");
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

query.asList() will pull everything in to memory. query.fetch() will return an Iterator allowing you to process each entity (in batches of 20 by default) without loading the entire result set in to memory first.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!