My Firestore Database :
i want to check if there is a field named "[email protected]" exist in Doc "D9GeGdTxarFruuuQklEO" only ,, not checking in all docs ,, anyway to do that in firestore Flutter ?
From cloud_firestore: ^0.14.0 to up you can check if a particular field exist in a documentSnapshot by doing this:
CollectionReference users = FirebaseFirestore.instance.collection('users');
var doc = await users.doc(id).get();
if(doc.exists){
Map<String, dynamic> map = doc.data();
if(map.containsKey('field')){// Replace field by the field you want to check.
var valueOfField = map['field'];
}
}
or you can also do this:
await _users.doc(id).get().then((doc){
if(doc.exists){
doc.data().forEach((key, value) {
if(key == 'field'){
var valueOfField = value;
}
});
}
});
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