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.
From the CLI, edit your index configuration file, with default filename firestore. indexes. json , and deploy using the firebase deploy command.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With