Home > database >  How to get data of a particular field in Cloud Firestore?
How to get data of a particular field in Cloud Firestore?

Time:08-17

We want to get "Ad soyad" data from our app for spesific place how can we do that?

enter image description here

CodePudding user response:

Just get the document and access its property.

// I don't know which documents you want to query, here it gets ALL of them
final docs = await firebase.collection('Çalisanlar').get();

// Just the first one as an example
final doc = docs.first;

// Print its `Ad soyad` property... or just do whatever you want with it.
print(doc['Ad soyad']);

CodePudding user response:

To get all the documents data:

void foo() async {
  final col = FirebaseFirestore.instance.collection('Calisanlar');
  final snapshot = await col.get();
  for (var qSnapshot in snapshot.docs) {
    final output = qSnapshot.get('Ad soyad');
  }
}

To get a single document data:

void bar() async {
  final doc = FirebaseFirestore.instance.collection('Calisanlar').doc('1xt...5n2');
  final snapshot = await doc.get();
  final output = snapshot.get('Ad soyad');
}
  • Related