I’m very new to Firebase. I’m building an e-commerce app using Firebase as the backend and Android Studio as the front end. In a DB, I have this tree:
Man
clothing
shorts
Product 1
Image ..
Name ..
Price ..
Size ..
Is it possible to have a size with multiple choices (for example Size 1, Size 2, Size 3, etc.)? How do I do?
2
Answers
As I see in your question, those fields are of type string. Such a field can only store a single value. If you want to store multiple values in a field, then you have to choose to use an array. So you can add all those sizes in an array. So your schema might look like this:
In this example, the
size
field is of type array and holdsS
at index0
,M
at index 1, and so on.Data in Firebase Realtime Database is stored as JSON and it is possible to use nested JSON as for your database structure. See sample database structure below: