There might be a case when u realize that you should have used autogenerated IDs for all your firebase documents in a collection and now you want to change the document IDs in your Collection ("collection_name") and also want to store their previous IDs as a new field ("prevID") in the new document then here's what you can do:-
FirebaseFirestore firebaseDb;
ArrayList<Map<String,Object>> data = new ArrayList<>();
firebaseDB.collection("collection_name").get.addOnSuccessListener(
queryDocumentSnapshots -> {
for (DocumentSnapshot d : queryDocumentSnapshots) {
Map<String,Object> map = d.getData();
map.put("prevID", d.getId());
data.add(map);
}
for(Map<String, Object> d : data){
Task<DocumentReference> dd = firebaseDb.collection("collection_name").add(d);
dd.addOnSuccessListener(new OnSuccessListener<DocumentReference>() {
@Override
public void onSuccess(DocumentReference documentReference) {
firebaseDb.collection("collection_name").document((String) d.get("prevID")).delete();
}
});
}
});