Reputation: 103
I want to check if a document in firestore exist when given a document id. So far I have tried this:
String getUserType(String uid) {
final result = Firestore.instance.collection('patients').document(uid).get();
if (result == null) {
return 'null';
} else {
return 'exist';
}
Upvotes: 0
Views: 439
Reputation: 3904
you can use result.exists
.
original post: https://stackoverflow.com/a/56465899/4465386
final result = await Firestore.instance
.collection('posts')
.document(docId)
.get()
if (result == null || !result.exists) {
// Document with id == docId doesn't exist.
}
Upvotes: 2