Firestore database duplication

Hi All! I have a user database with a sub-database called userFavorites and a tours database. My logic:

Once a user is logged in, they can view a tour in the UI, click on the heart icon, and that tour will be added to a separate Favorites page ( and Creates a Document in the userFavorites database). Well, every time I click on the heart icon, it keeps adding the same tour, over and over again... so, I'm getting alot of duplicates! Does anyone know how to avoid this? I've tried adding a conditional logic: if tourDocument name != userFavoritesDocument name then Create Document in userFavorites database else do nothing.

Any ideas?

11 replies