4
votes

I'm trying to create a simple system that allows users to create an account with info that they provided. Right now, I store all the data in a Collection users which has some Documents that represents users.
I'd like to keep some sensitive data of the user, such as the email address and phone number, private. In Firebase Database I would've created something like this:

  users: {
    uid: {
      public_info:...
      private_info:...
    }
  }

Protecting the data in here is pretty straight forward. I would simply write different rule sets for the private_info and public_info.
How would something like this be achieved in Firestore?

2

2 Answers

4
votes

Use different top-level collections for user public and private data, and set their rules appropriately.

0
votes

Depending on the use case you have two reasonably useful options:

Have a top level collection (public) with a sub collection called something like "private_data" (private) and grant access accordingly.

--OR--

Have a top level collection (private) with a sub collection called something like "public_data" (public) and grand access accordingly.