0

Suppose we have an image sharing app that we need to do is that allows people to choose from a set of tags for a particular picture. Like, say that I shared a photo on the beaches and my friend to like to add a tag of vacation to it. Now what we need are two options. First, the photo should display the tags assigned to and the second is that we could show the users photos based on any tag. So, for example, we want to show the users a list of pictures that have been assigned vacation tags.

Maadhav Sharma
  • 559
  • 1
  • 7
  • 18
  • 1
    While `firebase-realtime-database` and `google-cloud-firestore` are both part of Firebase, they are completely separate databases and the answer for each of these would be different. Please edit your question to include only the database you're actually using or going to use. – Frank van Puffelen Mar 24 '20 at 13:19

1 Answers1

1

For Realtime Database you'll typically end up with four collections: photos, tags, photoTags and tagPhotos. The former two contain the main data for each entity, while the latter two contain the relations between them.

When you have that, you'd read the relevant relations-node for the screen you want to display, and the read the individual entity nodes for that.

If tags are simple strings, you might of course not need the tags entities, as they're fully defined by their string value.

Also see:

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Actually I don't know what should I use. Could you pls suggest which should be used in this case. – Maadhav Sharma Mar 24 '20 at 15:03
  • That's a technology recommendation, which is off topic on Stack Overflow. But this should give you some pointers: https://firebase.google.com/docs/firestore/rtdb-vs-firestore – Frank van Puffelen Mar 24 '20 at 18:22