setIndexConfigurationFromJson method

Future<void> setIndexConfigurationFromJson(
  1. String json
)

Configures the persistent cache indexes of this instance from an index definition in the JSON format of the Firebase CLI (firestore.indexes.json, see https://firebase.google.com/docs/reference/firestore/indexes/#json_format). The queryScope of an index and the fieldOverrides are ignored. The indexes replace the ones that were configured before; an index that is configured again keeps its entries.

The index entries are written in the background while the app runs. A query against the local cache uses an index as far as it is filled, and the result of a query is the same with or without an index.

The future fails with an ArgumentError when json is not a valid index definition and with a StateError when this instance uses a memory cache. On a terminated instance it fails with the same FirestoreException as every other operation, whatever the cache.

Instead of creating cache indexes manually, consider persistentCacheIndexManager.enableIndexAutoCreation(), which lets the SDK decide whether to create cache indexes for queries running locally.

Implementation

Future<void> setIndexConfigurationFromJson(String json) async {
  client.verifyNotTerminated();
  if (!client.supportsFieldIndexes) {
    throw StateError('Cannot enable indexes when persistence is disabled');
  }
  return client.configureFieldIndexes(parseIndexConfiguration(json));
}