Reputation: 171
I'm new to iOS development also using Firebase. I want to know that if it's advisable to create sub collections under my users collection in my Firestore database so that each user once they have authenticated they will have access to their own data? Or shall i create new collections and reference the users ids once they authenticated with my login.
Reason i ask because there's multiple ways of using firebase but some ways aren't efficient and i want to know, what is recommended>
Upvotes: 0
Views: 78
Reputation: 1420
As was mentioned by @BurakAkkaş, @jnpdx and @Jay, Firestore is a NoSQL, document-oriented database. With that said, creating sub collections for a users
collection in a Firestore DB so that each user has access to their own data once authenticated may be (and may not be) a better approach than creating new collections and reference the users IDs once they authenticated with your login.
Structuring Data and Cloud Firestore Data model can help to understand how to structure your DB.
If you want to use sub collections and ensure that users can't access other users data, please refer to the Authentication article.
Without understanding the entire use case, it's difficult to make an accurate suggestion; your Firebase Structure is dependent on what queries you want to run. There are only some cases where a users data is only a users data that's never shared. Nesting collections makes those queries difficult to craft and not easily scalable.
You can provide your query details and a proposed structure to get further community support.
Upvotes: 1