- API Documentation >
- Result Classes >
- MongoDB\ChangeStream::key()
MongoDB\ChangeStream::key()
On this page
Definition
-
MongoDB\ChangeStream::key
Returns the index of the current event in the change stream.
The index of the first event in a change stream starts at zero and will increment by one for each subsequent event.
Return Values
The index of the current event in the change stream, or null
if there is no
current event (i.e. MongoDB\ChangeStream::valid()
returns
false
).
Examples
This example reports the index of events while iterating a change stream.
Assuming that a document was inserted, updated, and deleted while the above script was iterating the change stream, the output would then resemble:
See Also
MongoDB\Client::watch()
MongoDB\Collection::watch()
MongoDB\Database::watch()
- Iterator::key()
- Tailable Cursor Iteration
- Change Streams documentation in the MongoDB manual