title: i want to save and retrive all contacts to Firebase Firestore, need structure to save and retrive contacts
body: <p>I am developing an app, there's a functionality to get all the contacts of the user and upload it to server. Here I'm using Firebase Firestore as my backend. I can able to get all contacts without duplicates. Can someone please help, in which document structure I need to save the contact details of the user? Please tell me appropriate format so that it wont take much space in Firestore. </p>
  
  <p>And then..</p>
  
  <p>Once all the contacts are saved, I must be able to get the name of a contact using number what user is entering. This is my requirement. in short I would like to know how to save 2500 contact details for Firestore and how to read single contact name with help of contact number what user types in the edittext. (note : I heard like we cant save 2500 contact details of the user in one shot, something like batch should be used)</p>
  
  <p><a href="https://i.stack.imgur.com/5wyv2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5wyv2.png" alt="enter image description here"></a></p>
  
  <p>I tried this below code but it is saving only first 800 contacts only. </p>
  
  <pre><code>`private void doUploadContactstoCloud() {
          dialog.setCancelable(false);
          dialog.setMessage("Please wait we are configuring your request ...");
          dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
          dialog.show();
          listContacts = new ContactPresenter(this).fetchAllContacts();
          int j = listContacts.size();
  
          Log.d("sizejhfg",j+"");
  
          double size = listContacts.size();
          double ind = 0;
          Map&lt;String, Object&gt; contact = new HashMap&lt;&gt;();
          // Get a new write batch
          WriteBatch batch = db.batch();
          for (Contact con : listContacts) {
              for (int i = 0; i &lt; con.numbers.size(); i++) {
                  String number = formatnum(con.numbers.get(i).number);
                  if (number != null) {
                      if (!number.equals("0") &amp;&amp; number.length() &lt; 5) {
  
                          Map&lt;String, Object&gt; contactnumber = new HashMap&lt;&gt;();
                          contactnumber.put("name", con.name);
                          contactnumber.put("number", number);
                          contact.put(number,contactnumber);
                          DocumentReference item = db.collection(tonumber).document(number);
                          batch.set(item,contactnumber);
                          ind++;
                          if(ind==500){
                              doCommit(batch);
                              batch=db.batch();
                              ind=0;
                          }
                      }
                  }
              }
              //dialog.setProgress((int) (ind / size) * 100);
          }
          if(ind&gt;0){
              doCommit(batch);
          }
          prefManager.setisContactUpload(true);
          doDismissDialog();
      }` 
  </code></pre>
  
  <ol>
  <li>Please tell how I should save data in Firestore (structure)</li>
  <li>please tell me to read single contact name with help of number </li>
  </ol>