Creates a stream that tracks changes to documents in a Set.


toStream(): Stream<A>


The toStream() method creates a stream that tracks changes to documents in a Set.

You can only call toStream() on a Set from a supported source. The exact behavior of the method depends on this source. The calling Set isn’t changed.

Source Sets for streams support a limited number of transformations and filters.

A query that creates a stream returns a Stream.



Return value

Type Description


Stream token used to subscribe to the stream.


Collection streams

Calling toStream() directly on all() tracks any change to any document in the collection.


The query returns a stream token.


Index streams

Streams on indexes only send events for changes to the index’s terms or values fields.

For example, the following Product collection’s byCategory index has:

  • A term field of category

  • Value fields of name and price

collection Product {
  index byCategory {
    terms [.category]
    values [.name, .price]

The following query only tracks changes to the category, name, or price fields for Product documents with a category of sports.


Document streams

You can use streams to track changes to a Set containing a single document. These streams are only sent events when the document changes.

let product = Product.byId(392174614626697728)!

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email

Thank you for your feedback!