Skip to content

How to use CursorId? #566

@petr-buchin

Description

@petr-buchin

As far as I understand, the only way to use \MongoDB\Driver\CursorId instance is to get it's string representation.
But string representation of any CursorId instance is the same - "0".
For example:

$manager = new \MongoDB\Driver\Manager();

$query  = new \MongoDB\Driver\Query([]);
$cursor1 = $manager->executeQuery('test.test', $query);

$query2 = new \MongoDB\Driver\Query(['foo' => 'bar']);
$cursor2 = $manager->executeQuery('test.test2', $query2);

var_export((string) $cursor->getId()); // "0"
var_export((string) $cursor2->getId()); // "0"
(string) $cursor->getId() === (string) $cursor2->getId(); // true

Is it a bug, or \MongoDB\Driver\Cursor::getId() should not identify cursor uniquely? If latter, could you please explain, what is this method for and could you give an example of it's usage? Unfortunately documentation for this method is not very helpful.
I need this because I want to cache cursor instances in array by using some unique identificator as a key in array, but I don't know, whether I should use Cursor::getId() method or simply \spl_object_hash($cursor).

Thanks in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions