0

How can I fetch all map values added in an array using cloud firestore. The data is structured as: collection->documents->subcollection->document->array[{key:"someValue",key:"someValue2"},{key:"someValue",key:"someValue2"}]

Image for reference

2 Answers 2

1

If you want to fetch all the seat values once you can perform a simple get() query, then return the doc.data()'s .seats array or filter for seats from that data.

If you want to listen for realtime changes to the seats array you should create an onSnapshot listener where you can read and handle creations, updates, and deletions to the doc.data().

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for responding. This gives me an idea to work with.
0

Your question isn't very clear. Are you trying to fetch the entire array? In which case, fetch the document; the field 'seats' has the entire array.

Are you trying to search for a specific entry/map in the array? Simple answer: don't. The various ways of matching array entries all require exact match of the entire array element. (i.e., matching your '1' element would require {seat: "S2", selected: false} to match - you can't match just on "S2".

So when I say "don't", I mean structure your data differently. A general requirement of NoSQL and Firestore is to think about your queries first, and structure your data to allow for the queries you need. A "logical, compact structure" is often the wrong approach in NoSQL.

1 Comment

I actually want to fetch all the seats available in that particular array.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.