· Product designer

How to prevent duplicate docs in Firebase for save list collection?

Resolved

I have a collection in firebase of saved books. Users can save books from an api by taping a button called "Save book". That then triggers an action that creates a document to the saved books collection and fields are added for bookid, user reference, title, cover photo, and description. Each book has an ID, so each book has a unique id (bookid field) as a field in the saved book collection. What is the best way to avoid having users save the same book multiple times when they tap that button. I'm guessing I need to look up all book ids in the saved books collection associated with the user and set logic that says the id does not equal any of the existing ids. Not sure how to do that though.

4 replies