skip to Main Content

I have a list of URLs that are linked to the user. Currently, once the user adds those URLs to the app, I’m saving each URL as an individual document and then read any document that matches their UID.

Is this the right way to do it?

And with Firestore, is it cost per read per document or read per item no matter if there are 100 items in one document?

Just trying to wrap my head around it so any help would be great!

2

Answers


  1. In my opinion you should save URL’s in an array for every user. Because firebase charges you for one document read for each batch of up to 1000 index entries matched by the query.
    Check this link for more details:

    Login or Signup to reply.
  2. I’m saving each URL as an individual document and then reading any document that matches their UID. Is this the right way to do it?

    Not quite the best solution. While this solution will definitely work, it’s a little costly because you’ll have to pay a read operation for each document you read. In my opinion, the best option that you have is to store those URLs in an array in the user document. The schema should look like this:

    db-root
     |
     --- users (collection)
          |
          --- $uid (document)
               |
               --- urls: ["https://...", "https://...", "https://..."] (array)
               |
               --- //Other fields.
    

    Is it cost per read per document or read per item no matter if there are 100 items in one document?

    It’s always a read-per-document, no matter how many fields exist inside the document.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search