1

I have added a batch of about 500 fields to one of my documents in firestore.

Now Everytime I open the firestore web console, it takes about 1 minute to load, and browsing the data takes a lot of time.

Is this a common issue? What typical solutions would fix my problem?

Lambasoft
  • 909
  • 2
  • 14
  • 33
  • Why would you add 500 fields into a single document? – Alex Mamo Feb 11 '19 at 10:36
  • @AlexMamo Well I'm trying to a add the phone contacts of a user. Usually they're ~500 per user. I have something like: user_contacts_meta/$uid/contacts. I'm very new to firebase, and have been striving to learn more about it. I would appreciate your help – Lambasoft Feb 11 '19 at 10:40
  • 1
    @AlexMamo I have just watched your tutorial: https://www.youtube.com/watch?v=u3KwKQddPoo and I've seen you added every contact to a document. I will do that :) – Lambasoft Feb 11 '19 at 10:47
  • Good to hear that and thanks for watching that tutorial. Please also see my answer below. – Alex Mamo Feb 11 '19 at 10:52

1 Answers1

2

According to your comment:

Well I'm trying to a add the phone contacts of a user. Usually they're ~500 per user.

The best approach in this case would be to create a document for each contact and add it to a collection. Your schema might look like this:

Firestore-root
    |
    --- users (collection)
         |
         --- uid (document)
              |
              --- contacts (subcollection)
                   |
                   --- contactId (document)
                          |
                          --- //Contact details

Remember, according to the official documentation regarding Cloud Firestore Data model:

Firestore is optimized for storing large collections of small documents.

Beside that, if want to store large amount of data in one document, note that the documents have limits. So there are some limits when it comes to how much data you can put into a document. According to the official documentation regarding usage and limits:

Maximum size for a document: 1 MiB (1,048,576 bytes)

As you can see, you are limited to 1 MiB total of data in a single document.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • Thank you very much. Your solution worked perfectly! – Lambasoft Feb 11 '19 at 11:37
  • Hey Alex, sorry for bothering but I got one more question. Is it possible to obtain all the contactId from the contacts, without fetching their data? I'm trying to fetch users that have common contactId. Reference: https://stackoverflow.com/a/47273566/1194779 – Lambasoft Feb 11 '19 at 12:43
  • 1
    If you want to get only the ids of the documents, simply iterate over the collection and use `document.getId()`. That's it. If this is not what you are looking for, then please post another fresh question using its own [MCVE](https://stackoverflow.com/help/mcve), so me and other Firebase developers can help you. – Alex Mamo Feb 11 '19 at 12:47