Skip to main content

Changes API: How to Subscribe to Time Series Changes

  • Use the following methods to subscribe to Time Series Changes:
    • ForTimeSeries
      Track all time series with a given name
    • ForTimeSeriesOfDocument
      Overload #1: Track a specific time series of a chosen document
      Overload #2: Track any time series of a chosen document
    • ForAllTimeSeries
      Track all time series

The Subscribe method on the observable these methods return accepts only an IObserver object by default.
To instead subscribe with a delegate, like the change => ... lambda used in the examples below, add the System.Reactive package to your project.
This adds Subscribe overloads that take delegates, including ones with error and completion handlers.

ForTimeSeries​

Subscribe to changes in all time series with a given name, no matter which document they belong to, using the ForTimeSeries method.

Syntax​

IChangesObservable<TimeSeriesChange> ForTimeSeries(string timeSeriesName);

Parameters
timeSeriesNamestringName of a time series to subscribe to.
Return Value
IChangesObservable<TimeSeriesChange>Observable that allows to add subscriptions to time series notifications.

Example​

IDisposable subscription = store
.Changes()
.ForTimeSeries("Likes")
.Subscribe
(change =>
{
switch (change.Type)
{
case TimeSeriesChangeTypes.Delete:
// do something
break;
}
});

ForTimeSeriesOfDocument​

Use ForTimeSeriesOfDocument to subscribe to changes in time series of a chosen document.

  • Two overload methods allow you to
    • Track a specific time series of the chosen document
    • Track any time series of the chosen document

Overload #1​

Use this ForTimeSeriesOfDocument overload to track changes in a specific time series of the chosen document.

Syntax​

IChangesObservable<TimeSeriesChange> ForTimeSeriesOfDocument(string documentId, string timeSeriesName);

Parameters
documentIdstringID of a document to subscribe to.
timeSeriesNamestringName of a time series to subscribe to.
Return Value
IChangesObservable<TimeSeriesChange>Observable that allows to add subscriptions to time series notifications.

Example​

IDisposable subscription = store
.Changes()
.ForTimeSeriesOfDocument("companies/1-A", "Likes")
.Subscribe
(change =>
{
switch (change.Type)
{
case TimeSeriesChangeTypes.Delete:
// do something
break;
}
});

Overload #2​

Use this ForTimeSeriesOfDocument overload to track changes in any time series of the chosen document.

Syntax​

IChangesObservable<TimeSeriesChange> ForTimeSeriesOfDocument(string documentId);

Parameters
documentIdstringID of a document to subscribe to.
Return Value
IChangesObservable<TimeSeriesChange>Observable that allows to add subscriptions to time series notifications.

Example​

IDisposable subscription = store
.Changes()
.ForTimeSeriesOfDocument("companies/1-A")
.Subscribe
(change =>
{
switch (change.Type)
{
case TimeSeriesChangeTypes.Delete:
// do something
break;
}
});

ForAllTimeSeries​

Subscribe to changes in all time series using the ForAllTimeSeries method.

Syntax​

IChangesObservable<TimeSeriesChange> ForAllTimeSeries();

Return Value
IChangesObservable<TimeSeriesChange>Observable that allows to add subscriptions to time series notifications.

Example​

IDisposable subscription = store
.Changes()
.ForAllTimeSeries()
.Subscribe
(change =>
{
switch (change.Type)
{
case TimeSeriesChangeTypes.Delete:
// do something
break;
}
});

TimeSeriesChange and TimeSeriesChangeTypes syntax​

The notification object delivered to subscribers when a time series changes.

class TimeSeriesChange
{
TimeSeriesChangeTypes Type
string Name
string DocumentId
string CollectionName
DateTime From
DateTime To
string ChangeVector
}

PropertyTypeDescription
TypeTimeSeriesChangeTypesTime series change type enum
NamestringTime Series Name
DocumentIdstringTime series Document Identifier
CollectionNamestringTime series document Collection Name
FromDateTimeTime series values From date
ToDateTimeTime series values To date
ChangeVectorstringTime series Change Vector

In this article