How can I edit this code so I can create my own custom document id in Firestore?
users.add(new Accounts(fname, lname, uname, email, pass)).addOnSuccessListener(new OnSuccessListener<DocumentReference>() {
@Override
public void onSuccess(DocumentReference documentReference) {
Toast.makeText(CreateAccount.this, "Data saved to FireStore", Toast.LENGTH_SHORT).show();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.d(TAG, e.toString());
}
});
If you want to create a custom document id insead of the one that is generated when using CollectionReference's add() method which:
You should use DocumentReference's set() method:
If you want to get the document id that is generated or use a custom id in your reference, then please use following lines of code: