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.
And then..
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)
I tried this below code but it is saving only first 800 contacts only.
`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<String, Object> contact = new HashMap<>();
// Get a new write batch
WriteBatch batch = db.batch();
for (Contact con : listContacts) {
for (int i = 0; i < con.numbers.size(); i++) {
String number = formatnum(con.numbers.get(i).number);
if (number != null) {
if (!number.equals("0") && number.length() < 5) {
Map<String, Object> contactnumber = new HashMap<>();
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>0){
doCommit(batch);
}
prefManager.setisContactUpload(true);
doDismissDialog();
}`
- Please tell how I should save data in Firestore (structure)
- please tell me to read single contact name with help of number
