Firebase indexes "order": "ARRAYS"

Viewed 456

What should we use in indexes.json file for arrays query?

"collectionGroup": "posts",
      "queryScope": "COLLECTION",
      "fields": [
        {
          "fieldPath": "category",
          "order": "ASCENDING"
        },
        {
          "fieldPath": "tags",
          "order": "***ARRAY?***"
        },

In web interface we have "arrays" option. enter image description here

1 Answers

You want "arrayConfig": "CONTAINS".

"collectionGroup": "posts",
  "queryScope": "COLLECTION",
  "fields": [
    {
      "fieldPath": "category",
      "order": "ASCENDING"
    },
    {
      "fieldPath": "tags",
      "arrayConfig": "CONTAINS"
    },

In the future, you can actually figure this out for yourself by running firebase init firestore in a new folder, and it will create the indexes file based on what you created in the console. Also in the future, the JSON will be documented.

Related