My requirement is, when a user Mr.ABC install the app it will take all the contacts of the user and save to Firebase Firestore. And when another user Mr.XYZ installs the app in his device, it will take all contacts of XYZ and save to Firebase. Likewise whoever installs the app it will take the contacts and save to Firebase Firestore. Now my read operation should be, Mr.ABC will type XYZ number in EditText and in firebase, I have to look into XYZ contact details and find out ABC's number and get the name in which XYZ saved in his contact. So when ABC type XYZ number, ABC can able to find out in which name XYZ saved ABC's number. Please help me in which structure I should save the contacts in firebase and in how can I read the data. I would like to know the efficient way to do this. As I'm not good with database, helping me with exact code will be much more helpful. Please help.
I have tried the below code but only 800 contacts are stored to Firestore instead of 2500, moreover i'm not sure the db structure I'm using is right or wrong. I have zero knowledge on DB.
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();
}`