I know that in Realtime Database
I could get the push ID
before it was added like this:
DatabaseReference databaseReference= FirebaseDatabase.getInstance().getReference(); String challengeId=databaseReference.push().getKey();
and then I could add it using this ID.
Can I get it also in the Cloud Firestore?
Set the data of a document within a collection, explicitly specifying a document identifier. Add a new document to a collection. In this case, Cloud Firestore automatically generates the document identifier. Create an empty document with an automatically generated identifier, and assign data to it later.
This is covered in the documentation. See the last paragraph of the add a document section.
DocumentReference ref = db.collection("my_collection").doc(); String myId = ref.id;
const db = firebase.firestore(); const ref = db.collection('your_collection_name').doc(); const id = ref.id;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With