Does the list operation load integer data on first call?

Suppose I have a very large collection and I select it

MongoCursor<MyClass> answer = myCollection.find().as(MyClass.class);  

      

Will Jongo / Mongo load the entire collection on the first call, or will it incrementally load the data while I iterate answer

?

+3


source to share


1 answer


Jongo MongoCursor

uses Mongo regular DBCursor

under the hood. DBCursor

loads items lazily (as usual, all cursors). Ie, your entire collection will not be loaded into memory, it will be lazy loaded while you iterate over the cursor.

Relevant source from Jongo, where cursor

- DBCursor

.



public E next() {
    if (!hasNext())
        throw new NoSuchElementException();

    DBObject dbObject = cursor.next();
    return resultHandler.map(dbObject);
}

      

+2


source







All Articles