MongoDB\ChangeStream::rewind()
For the complete MongoDB documentation index, see www.mongodb.com/docs/llms.txt
MongoDB\ChangeStream::rewind()
Definition
Rewinds the change stream and attempts to load the first event.
function rewind(): void
This method should be called at the start of change stream iteration.
Note:
Rewinding the change stream does not guarantee that there will be a current event to access. You should still call [MongoDB\ChangeStream::valid()](https://www.mongodb.com/docs/php-library/current/reference/method/mongodbchangestream-valid.md#mongodb-phpmethod-phpmethod.MongoDB-ChangeStream--valid-- to check for a current event at each step of iteration. After initially rewinding the change stream, [MongoDB\ChangeStream::next()](https://www.mongodb.com/docs/php-library/current/reference/method/mongodbchangestream-next.md#mongodb-phpmethod-phpmethod.MongoDB-ChangeStream--next-- should be used to iterate further.
Errors/Exceptions
MongoDB\Driver\Exception\LogicException if this method is called after a call to [MongoDB\ChangeStream::next()](https://www.mongodb.com/docs/php-library/current/reference/method/mongodbchangestream-next.md#mongodb-phpmethod-phpmethod.MongoDB-ChangeStream--next-- (i.e. the underlying MongoDB\Driver\Cursor has already been advanced).
MongoDB\Driver\Exception\RuntimeException for other errors at the extension level (e.g. connection errors).
See Also
-
[
MongoDB\Client::watch()](https://www.mongodb.com/docs/php-library/current/reference/method/mongodbclient-watch.md#mongodb-phpmethod-phpmethod.MongoDB-Client--watch-- -
[
MongoDB\Collection::watch()](https://www.mongodb.com/docs/php-library/current/reference/method/mongodbcollection-watch.md#mongodb-phpmethod-phpmethod.MongoDB-Collection--watch-- -
[
MongoDB\Database::watch()](https://www.mongodb.com/docs/php-library/current/reference/method/mongodbdatabase-watch.md#mongodb-phpmethod-phpmethod.MongoDB-Database--watch-- -
[Tailable Cursor Iteration](https://www.mongodb.com/docs/php-library/current/crud/query/cursor.md#std-label-php-tailable-cursor
-
Change Streams documentation in the MongoDB manual
