serjo macken
serjo macken

Reputation: 445

Check if string already exists in a field in cloudfirestore field and flutter

I have a collection called IDS in cloudfirestore, inside it, there is a document called IDs,inside this document I have fields starting with ID1 to reach almost ID14000,The user enters his id inside a textfield,I need to check if the id exists in the fields thanks.

Upvotes: 1

Views: 1596

Answers (1)

blaneyneil
blaneyneil

Reputation: 3232

final CollectionReference dbIDS = Firestore.instance.collection('IDS');

QuerySnapshot _query = await dbIDS
    .where('ID', isEqualTo: theUserInputID)
    .getDocuments();

if (_query.documents.length > 0) {
  // the ID exists
}

Upvotes: 2

Related Questions