Ad

How To Show The Documents Made By A Certain Member In Firestore (Android)?

I have an application where members can post content, but then I have a problem. My problem is that I want to do an activity where the publications of only the author member are shown but Firestore asks me to create an Index to do this, the problem is that the document of each member is based on its UID.

For example: My UID is: x54asdASD544

Then I try to make this query:

Query query = mMembersDB.document("POST").collection("x54asdASD544").whereEqualTo("type", "public").orderBy("date");

That's when Firestore asks me to create an index, then I create it and it works perfect after creating the index, but if I'm going to do the same, to see the publications of another author, then he asks me to create another index.

For example:

Query query = mMembersDB.document("POST").collection("x54assds").whereEqualTo("type", "public").orderBy("date");

The UID changed, then the previously created index does not work anymore.

  • Any solution to be able to repair this?
  • Any way to create indexes automatically?
Ad

Answer

Each uniquely named collection and subcollection must have its own indexes. You can't share index definitions between collections. They must be defined separately. There is no way to automatically create indexes.

Naming a subcollection based on a UID doesn't sound like a very effective way to model your data. Consider putting all the documents in one collection, put the UID as a field to those documents, and use the UID as a filter to find what you want.

Ad
source: stackoverflow.com
Ad