MongoDB Realm allows you to watch a collection and receive client-side database events whenever documents in the collection are inserted or modified. This enables you to develop real-time and collaborative applications without the overhead and complexity of alternatives such as long polling.
Realm uses MongoDB change streams on watched collections to listen for changes and broadcast them to any client applications that are watching documents in the collection at the time of the event. Realm supports watching any change on a collection and watching changes that match a certain filter.
collection.watch() API provides real-time notifications to client apps
whenever a document in a specified collection changes. This is useful for cases
where you want to know when something happened while a user is online. For
- Track the location of a delivery
- Get the most up-to-date score and stats for a game
- Update a chat thread when a user sends a new message
Change streams returned by the
watch() API are not resumable and only
process changes while a user is online. As a result, they are not generally
suited for use cases where you must ensure that every update is processed. To
handle reactive business logic like this, use triggers.
For code examples of watching collections, refer to the client SDKs: