Skip to content
This repository was archived by the owner on Nov 11, 2020. It is now read-only.

Conversation

jwage
Copy link
Member

@jwage jwage commented Jan 20, 2012

When used it will return a different type of cursor that eagerly fetches all documents when you start iteration instead of one document per iteration. So it loads all data in to memory before starting iteration.

Without eager cursor:

$qb = $this->conn->selectCollection('dbname', 'collection')->createQueryBuilder();
$cursor = $qb->getQuery()->execute();
foreach ($cursor as $document) { // only loads one $document at a time
}

With eager cursor:

$qb = $this->conn->selectCollection('dbname', 'collection')->createQueryBuilder();
$qb->eagerCursor(true);
$cursor = $qb->getQuery()->execute();
foreach ($cursor as $document) { // loads all documents in to memory before iterating
}

This will tie in to #40 where we have retry functionality. In order to benefit from retries on cursors, you will have to use an eager cursor so that the data fetching is all done before iteration starts so that if a cursor error happens you can try again with a new cursor.

… it will return a different type of cursor that

eagerly fetches all documents when you start iteration instead of one document per iteration. So it loads all data in to memory before starting iteration.
@jmikola
Copy link
Member

jmikola commented Jan 20, 2012

The benefit of this vs. using toArray() is that object hydration can still be done on-demand, but the cursor's raw data from MongoDB is exhausted in the first iteration, correct?

@jwage
Copy link
Member Author

jwage commented Jan 20, 2012

Actually it doesn't behave that way right now. It fetches the data and hydrates together.

@jwage
Copy link
Member Author

jwage commented Jan 20, 2012

I might tweak it to work that way so hydration is still on demand but the data is pulled all at once.

@jwage
Copy link
Member Author

jwage commented Jan 20, 2012

Actually thinking about it I'm not going to do that as it doesn't really give much of an added benefit. If we conclude otherwise later I can enhance it.

jwage added a commit that referenced this pull request Jan 20, 2012
Add functionality that allows eagerCursor(true) on query builders
@jwage jwage merged commit 3ea8b7f into master Jan 20, 2012
jmikola pushed a commit to jmikola/mongodb-odm that referenced this pull request Mar 11, 2015
This functionality was added to the Doctrine MongoDB layer here: doctrine/mongodb#41
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants