skip to Main Content

I am working on a flutter project where I want a function that returns the Document ID. The only thing availabe is document field that is email or name.

Firestore Database.

What I want is:

if (email == email) {
  return documentID;
}

2

Answers


  1. new Promise((resolve, reject)=>{
      db.collection('users').get().then((snapShot)=>{
        const ids = [];
        snapShot.forEach((doc) => {
          const data = doc.data();
          if (data.email || data.name) {
            ids.push(doc.id);
          }
        });
        resolve(ids);
      });
    });
    
    
    Login or Signup to reply.
  2. As much as I don’t understand your request, I’ll make a guess.

    I guess you want to get the id of this document when it matches the value you want.

    String? id;
    await FirebaseFirestore.instance.collection('users').where('email', isEqualTo: 'email').get().then((value) => id = value.docs.first.id);
    
    print(id); //DocumentID
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search