0
votes

I'm creating a shared todo list/checklist application with flutter and for the database I use Firestore. The user belongs to a group and each group has a list of todo-lists. Each todo-lists contains to-do items.

As of this moment, a todo-list is a document that contains a list of documents with a todo-item. If a todo-list contains 50 todo-items for example, I will be charged for 50 document reads when the user opens the todo-list. The users also subscribe with snapshot to changes to any of the todo-items. Each change will be charged as an update and a read.

My concern is that the initial 50 document reads will be too much every time the todo-list is opened. I'm considering making a todo-list document with an array property or a flat list with todo-items inside. When the todo-list is opened, I will only be charged 1 document read. But this list is also real-time and my question now is what does this mean? Will, the todo-list document be downloaded once again with the 50 items or will it only download the changes to the array? My concern with this approach is that the user will download too much data even with a simple change to a single todo-item or am I wrong with this? Does someone know a better approach or do I make these trade-offs?

Also, users are limited to 100 todo-items in a single list.

1
There was a similar question. This answer may be useful. - Dharmaraj
Thanks for the suggestion, but that post is an extension of my current approach with a document for each to-do-item. I'm look for a different approach with arrays or something else - Dev Db
You'll run into some issues that way. A document can only have data upto 1 MB. You cannot query a specific task easily and so on - Dharmaraj
That's why there's a limit on the amount of todo-items per list to avoid the 1MB limit - Dev Db
Can you please explain why you don’t want to use the previous approach using collections and why you are looking for a new solution with Arrays? If you want to continue with the previous approach, to reduce the number of reads: create either a new collection or a subcollection for groups and you can store the information of users in the subcollection and the tasks in the to-do list in the same document, so that whenever someone accesses the list, they fetch all the info inside the list with just one document. - Farid Shumbar

1 Answers

0
votes

You can try to use a hybrid between the two - that is, have a TodoList document which contain a collection of TodoListItems and that document can contain more than one item in it, let's say you'll save 30 items in it and on the 31st item you'll create a new TodoListItems document and start to fill it.

That way you won't get charged for 50 documents, just because you have 50 items in the TodoList, in this example of 30 items per document you'll get charged for 2.

I think that this way you'll be able both have lists that are larger than the 1MB limit, but won't incur to costs of a single document per item.