Batch write
/**
*
* @param storeID
* @param customerDocIdList
* @param groupName
* @param dataOperationCompletionListener
*/
@Override
public void tagGroupIntoCustomers(String storeID, ArrayList<String> customerDocIdList,final String groupName, final DataOperationCompletionListener dataOperationCompletionListener) {
//Get a new Write batch
WriteBatch writeBatch = billerFirestoreDB.batch();
DocumentReference customerDocumentReference = null;
//Reading Selected customer which is add in to a group
for (int customerId = 0; customerId < customerDocIdList.size(); customerId++) {
//Create reference of each customer
customerDocumentReference = billerFirestoreDB.collection(BillConstants.VENDORS_CUSTOMER).document(storeID).collection(BillConstants.CUSTOMERS).document(customerDocIdList.get(customerId));
//Update particular reference,fieldsKey,fieldValue
writeBatch.update(customerDocumentReference, BillConstants.TAG_GROUP, groupName);
}
//commit batch
writeBatch.commit().addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
dataOperationCompletionListener.operationCompleted(true);
}
});
}