Search code examples
firebaseflutterdartgoogle-cloud-firestoresnapshot

How to get document snapshot where name in data map in collection in flutter


I am trying to get document snapshot by searching by recipe name and recipe name sore in data:

Firebase Firestore image

Query query = FirebaseFirestore.instance
    .collection("recipes")
    .where("name", isEqualTo: "test");
QuerySnapshot querySnapshot = await query.get();

Solution

  • Your name field stored inside an object data. So the query should be on data.name

    Query query = FirebaseFirestore.instance
        .collection("recipes")
        .where("data.name", isEqualTo: "test");
    

    To read about the nested Objects and . notation, see the documentation on fields in nested objects.