I have a class called User
and i created a List<User> users;
, Now i need to add this list to Firestore, What i did is that i iterated over the list and add every object separately as Firestore accept only HashMaps or objects and here is the code
for (User user:users){
db.collection("Users").document(user.getUserNumber()).set(user)
.addOnCompleteListener(MainActivity.this, new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()){
Log.e(TAG, "DocumentSnapshot added with ID: " + task.getResult());
}else Log.e(TAG, "Error adding document", task.getException());
}
});
}
My question is there is any way to add the whole list to Firestore with one request instead of calling the api as many times as the list size ??