1

In my firestore database I'm naming documents by combining two users ids and a '-' between them, like this:

/collection/{userID123-userID456}

For every user I want to query all those documents that his id is one of the two (the string either starts or ends with his id).

It works well with my security rules: allow read: if request.auth.uid in docID.split('-') but I did'nt find a way to do so with get/query for the document's id.

I was trying to query those documents' keys but it seems that this security rule blocks that kind of operation.

Thanks for your help!

YosefBro
  • 596
  • 1
  • 7
  • 17

1 Answers1

6

There is no way to search for documents whose ID contains a substring, nor for those whose ID ends with a substring. The only possibility is to find documents whose ID starts with a substring.

You will instead have to maintain a list of the collections for each specific user. You can then still use security rules to ensure the user can only access the collections their ID is mentioned in.

Also see:

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Thank you for your quick answer! I guess it will be better if I just change my data structure then. – YosefBro Aug 25 '20 at 13:42