You are currently browsing legacy 3.0 version of documentation. Click here to switch to the newest 4.2 version.

We can help you with migration to the latest RavenDB

Contact Us Now
see on GitHub

Changes API: How to subscribe to index changes?

Following methods allow you to subscribe to index changes:

ForIndex

Index changes for one index can be observed using ForIndex method.

Syntax

IObservableWithTask<IndexChangeNotification>
	ForIndex(string indexName);

Parameters
indexName string Name of an index for which notifications will be processed.
Return value
IObservableWithTask<IndexChangeNotification> Observable that allows to add subscriptions to notifications for index with given name.

Example

IDisposable subscription = store
	.Changes()
	.ForIndex("Orders/All")
	.Subscribe(
		change =>
		{
			switch (change.Type)
			{
				case IndexChangeTypes.IndexAdded:
					// do something
					break;
				case IndexChangeTypes.IndexDemotedToAbandoned:
					// do something
					break;
				case IndexChangeTypes.IndexDemotedToDisabled:
					// do something
					break;
				case IndexChangeTypes.IndexDemotedToIdle:
					// do something
					break;
				case IndexChangeTypes.IndexMarkedAsErrored:
					// do something
					break;
				case IndexChangeTypes.IndexPromotedFromIdle:
					// do something
					break;
				case IndexChangeTypes.IndexRemoved:
					// do something
					break;
				case IndexChangeTypes.MapCompleted:
					// do something
					break;
				case IndexChangeTypes.ReduceCompleted:
					// do something
					break;
				case IndexChangeTypes.RemoveFromIndex:
					// do something
					break;
			}
		});

ForAllIndexes

Index changes for all indexex can be observed using ForAllIndexes method.

Return value
IObservableWithTask<IndexChangeNotification> Observable that allows to add subscriptions to notifications for all indexes.

Syntax

IObservableWithTask<IndexChangeNotification>
	ForAllIndexes();

Example

IDisposable subscription = store
	.Changes()
	.ForAllIndexes()
	.Subscribe(change => Console.WriteLine("{0} on index {1}", change.Type, change.Name));

Remarks

Information

To get more method overloads, especially the ones supporting delegates, please add Reactive Extensions package to your project.