Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the JSON format for a firestore composite index including an array?

Tags:

I want to filter a collection (let's call it documents) using array-contains on one column (say keywords) and sort by another column (say name).

I am able to create this composite index in the firebase console, but I can only guess at the format for adding it to firestore.indexes.json.

It's unfortunate we can't download the index file from the console.

like image 496
plediii Avatar asked Oct 30 '18 19:10

plediii


People also ask

What file should be used for firestore indexes firestore indexes JSON?

From the CLI, edit your index configuration file, with default filename firestore. indexes. json , and deploy using the firebase deploy command.

What is composite index in firestore?

Composite indexes A composite index stores a sorted mapping of all the documents in a collection, based on an ordered list of fields to index. Note: You can have at most one array field per composite index. Cloud Firestore uses composite indexes to support queries not already supported by single-field indexes.

Does firestore use JSON?

Cloud Firestore data has a nested JSON-like structure, but there's no way to export documents or collections to JSON via the Firebase Console.


1 Answers

Set the mode to ARRAY_CONTAINS:

{
      "collectionId": "documents",
      "fields": [
        {
          "fieldPath": "keywords",
          "mode": "ARRAY_CONTAINS"
        },
        {
          "fieldPath": "name",
          "mode": "ASCENDING"
        }
  ]
}

You can also list your current Cloud Firestore indexes in JSON from the Firebase CLi:

firebase firestore:indexes
like image 144
Juan Lara Avatar answered Sep 20 '22 04:09

Juan Lara