How do I select this in the Firebase Cloud Firestore database?

Asked

Viewed 689 times

0

how do I do this kind of select in the Firebase Cloud Firestore database ?

 _results = (await connection.query('select id from produtos where numero_serie = $_numeroSerie'))

I need to get the product id that is in the firebase database where the column numero_serie has the same value as variable _numeroSerie

2 answers

1


This worked and does not repeat the same variable in the bank

final QuerySnapshot result = await Future.value(Firestore.instance
    .collection("lockers")
    .where("numero_serie", isEqualTo: "$_numeroSerie")
    .limit(1)
    .getDocuments());

final List<DocumentSnapshot> documents = result.documents;
if (documents.length == 1) {
  confirmacao(context);
} else {
  await Firestore.instance
      .collection("lockers")
      .document()
      .setData({"numero_serie": _numeroSerie});
}
}

1

// Creates reference for Collection products

var produtosRef = db.collection("produtos");

// Creates the query

var query = produtosRef.where("numero_serie", "==", $_numeroSerie)

See the official Firebase documentation in English here.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.