firebasegoogle-cloud-platformgoogle-cloud-firestore

Adding exemptions in Firebase automatic indexing


I'm storing data in firebase with this structure:

/aggregate_data/{user id}/{product id}/data

The aggregate_data collection is the root collection ID and the rest subcollections and documents under it except data are dynamically generated. The data stored under data document is a map with a structure:

{
  'YYYYMMDD': {
     'field1': value1,
     'field2': value2,
     'field3': value3,
     'field4': value4,

  },
  .
  .
  .
  .
  .
  'YYYYMMDD': {
     'field1': value1,
     'field2': value2,
     'field3': value3,
     'field4': value4,

  },

}

The data inside this data document has now reached a point where it's not allowing me to add (update) more data in this map since it's being auto-indexed by Firebase and this error is produced as a result:

google.api_core.exceptions.InvalidArgument: 400 too many index entries for entity

I tried adding an exception in indexing to prevent indexing on this document so that I can add more data but not sure if I'm doing it the right way. So far I've tried the combinations shown in this screenshot:

enter image description here

Where sessions is one of the fields nested inside the map. Please note that the map keys YYYYMMDD are dynamically generated and contain date strings. What would be the right Collection ID & Field path combinations needed for me to stop the indexing so that I can add more data?


Solution

  • Seemed to be any easy one since the subcollection in my case was a dynamic one I used the * wildcard as Collection ID and the field names field1, field2 etc. were known so I had to add them specifically to prevent them from being auto-indexed and this fixed the issue. One such example is given below for field name sessions: enter image description here