I have to query a collection to find a document by documentID just created, but I need to get and pass the DocumentSnapshot instead of a DocumentReference. How can I get it? I have this
if (_pfKey.currentState.validate()) {
_pfKey.currentState.save();
String ragsoc = _cognome + " " + _nome;
// DocumentReference ds =Firestore.instance.collection('pazienti').document(this.record);
for (i = 0; i < ragsoc.length; i++) {
indici.add(ragsoc.substring(0, i + 1).toLowerCase());
}
Map<String, dynamic> miorecord = {
"nome": _nome,
"cognome": _cognome,
"datanascita": _datanascita,
"luogonascita": _luogonascita,
"codicefiscale": _codfisc,
"cap": _cap,
"provincia": _provincia,
"indirizzo": _indirizzo,
"citta": _citta,
"ciclo": _ciclo,
"figli": _figli,
"patologiemam": _patomamm,
"tormonale": _tormonale,
"searchIndex": indici
};
DocumentReference ds = await Firestore.instance.collection('pazienti').add(miorecord).catchError((e) {
print(e);
});
DocumentSnapshot documentSnapshot = ds.firestore.collection('pazienti').document(ds.documentID);
Thank you:/
Try Saving data using your own customId and retrieve using that id.
Try this:-
Firestore _fireStore = Firestore.instance;
await _fireStore
.collection('fireStoreCollectionName')
.document('customId')
.setData(miorecord);
DocumentSnapshot documentSnapshot = await _fireStore
.collection('fireStoreCollectionName')
.document('customId')
.get();
Map mapName = documentSnapshot.data;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.