· Learning FF

Best Firestone database/collection structure

Project Settings

Hello,

I would appreciate some advice on how to best structure my project when it comes to Firestore collections/sub-collections, etc.

My application is very simple: users will scan books and then have the possibility to add the scanned book to their favorites and to mark it as read.

The current structure I have is the following:

  • users collection

  • books collection which contains a field called "scanned_by_user" to link the book to the user, another one called "is_favorite" and a last one called "is_read"

So far so good but what I am now realizing is that if 50 users are scanning the same book, I will have 50 times the document in my books collection.

Is this a bad thing? How can I improve this scheme to be more efficient?

Reading through FF documentation these are the options I can see:

  • create a sub-collection to books to store the user info (it's id, if he has added the book to its library and if he has read the book)

  • same as the point above but create a collection and not a sub-collection? I am not sure I understood the differences between the 2 cases

  • create a new field in the books collection of type array that will contain the doc. ref. to the user and the 2 booleans (is_favorite and is_read)

  • Each of the 3 points above talk about modifying the "books" collection, but could the solution be to update the "users" collection to add all this info. I am not convinced but want to drop the idea just in case.

Thanks for your thoughts!

What have you tried so far?

Understanding different Firestore DB structures/concepts.

Did you check FlutterFlow's Documentation for this topic?
Yes