Suresh kumar
Suresh kumar

Reputation: 1

How to query a map on array on firestore

I am using flutter for mobile development and I need to query an map on array in firestore.

My code :

FirebaseFirestore.instance
            .collection("/notes")
            .where({
              "semester 1"
            }, arrayContains: [
              {"ec321ece"}
            ], isNotEqualTo: [
              {"value321ece"}
            ])
          
            .snapshots()
            .listen((value) => value.docs.forEach((element) {
                 
                 print("${element.data()}");

                }));

my firestore image

Please help me.

Upvotes: 0

Views: 401

Answers (1)

Jason Berryman
Jason Berryman

Reputation: 4898

It is not possible to use array contains with maps, in the way that you are trying. There are a couple of options:

Array of Maps and Array of Keys

Have your existing semester 1 array with the maps, but also add a second array called Semester 1 IDs and store only the values (as strings) that you want to search for.

Sub-collections

Using a semesters sub-collection of your notes document will give you greater flexibility in your searching. Also, if your notes document grows as you add more semesters, it may get bigger than 1MB and will be a heavy payload if listing notes in your UI.

Upvotes: 1

Related Questions