Indexes on the firestore collection with the same name on different "tracks"

In my firestore database, I use the same collection name in different parts of my hierarchy. For example, imagine a site like stackoverflow with the following 2 collections

/questions/{questionId}/votes/ /questions/{questionId}/answers/{answerId}/votes/

So now I want to create an index in one of these two collections. I would expect the firestore to require some kind of “wildcard” paths, as I used above to identify the data for indexing. However, instead they only need the name of the collection: in this case, “voices”.

So, if I put the index on the “votes”, is it applicable to both of these collections? Is there a way to put an index in one of these collections and not the other? Are unique collection names recommended to avoid this problem?

+4
source share
1 answer

TL DR:

Yes . Indexes are based on the collection identifier. This applies to those that we automatically create for you in separate fields, as well as to composite indexes that you create manually. If they are semantically different indexes, we recommend that you provide them with unique identifiers, so you can use question_votesand answer_votes.

More details

- , . votes, .

, , , , , ( ). .

, 200 , , - , , /users/{user_id}/blog_posts/{post_id}, blog_posts ( !)

+4

Source: https://habr.com/ru/post/1692323/


All Articles