Search code examples
firebasegoogle-cloud-firestorefirebase-cli

Firebase indexes "order": "ARRAYS"


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


Solution

  • 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.