Search code examples
fluttergoogle-cloud-firestorecloud

How can i get document id in flutter


How can i get document id which 'content' is 'test2' ? enter image description here i try like this.. but the condition does not work.

 ref.where(ref.doc('content') == 'test2').get().then((QuerySnapshot snapshot){
      snapshot.docs.forEach((document){
        print(document.id);
      });
 });

How can I get document id of specific document? (I use flutter and cloud firestore)


Solution

  • Assumingref is your collection reference, use this:

    await ref.where('contents', isEqualTo: 'test2').get().then((QuerySnapshot snapshot){
          snapshot.docs.forEach((document){
            print(document.id);
          });
     });