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

Commit

Permalink
Do not track multiple hints/sorts in Cursor
Browse files Browse the repository at this point in the history
Successive calls to MongoCursor::hint() or sort() will overwrite the previous value, so there is no reason to store multiple values in the Doctrine class. ODM does seem to depend on the hints property to track UnitOfWork hints (entirely different than MongoDB index usage hints), but that should be changed upstream.
  • Loading branch information
jmikola committed Apr 23, 2013
1 parent 9e8ec99 commit a66ffbc
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions lib/Doctrine/MongoDB/Cursor.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ class Cursor implements Iterator
protected $numRetries;
protected $query = array();
protected $fields = array();
protected $hints = array();

This comment has been minimized.

Copy link
@idetia

idetia Apr 30, 2013

After apply this change I obtain the next error:

Argument 3 passed to Doctrine\ODM\MongoDB\Hydrator\HydratorFactory::hydrate() must be an array, null given

This comment has been minimized.

Copy link
@jmikola

jmikola Apr 30, 2013

Author Member

doctrine/mongodb-odm#565 is the PR where I'm tracking ODM changes for this functionality. I'll make a note of this there.

I would not rely on using 1.1.x of doctrine/mongodb until ODM's composer.json file is properly updated in a subsequent beta release.

protected $hint;
protected $immortal;
protected $options = array();
protected $batchSize;
protected $limit;
protected $skip;
protected $slaveOkay;
protected $snapshot;
protected $sorts = array();
protected $sort;
protected $tailable;
protected $timeout;

Expand Down Expand Up @@ -99,8 +99,8 @@ public function getFields()
public function recreate()
{
$this->mongoCursor = $this->collection->getMongoCollection()->find($this->query, $this->fields);
foreach ($this->hints as $hint) {
$this->mongoCursor->hint($hint);
if ($this->hint !== null) {
$this->mongoCursor->hint($this->hint);
}
if ($this->immortal !== null) {
$this->mongoCursor->immortal($this->immortal);
Expand All @@ -123,8 +123,8 @@ public function recreate()
if ($this->snapshot) {
$this->mongoCursor->snapshot();
}
foreach ($this->sorts as $sort) {
$this->mongoCursor->sort($sort);
if ($this->sort !== null) {
$this->mongoCursor->sort($this->sort);
}
if ($this->tailable !== null) {
$this->mongoCursor->tailable($this->tailable);
Expand Down Expand Up @@ -204,7 +204,7 @@ public function hasNext()

public function hint(array $keyPattern)
{
$this->hints[] = $keyPattern;
$this->hint = $keyPattern;
$this->mongoCursor->hint($keyPattern);
return $this;
}
Expand Down Expand Up @@ -339,7 +339,7 @@ public function sort($fields)
}
$fields[$fieldName] = (integer) $order;
}
$this->sorts[] = $fields;
$this->sort = $fields;
$this->mongoCursor->sort($fields);
return $this;
}
Expand Down

0 comments on commit a66ffbc

Please sign in to comment.