Ask Your Question
0

In Firebase, what is the method for querying maps that are nested within an array field?

asked 2023-05-20 01:18:46 +0000

pufferfish gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-05-20 01:48:01 +0000

lakamha gravatar image

To query maps nested within an array field in Firebase, you can use the array-contains query method.

For example, let's say you have a collection of users, and each user document has an addresses field that is an array of maps containing the user's various addresses. To query for users who have an address in a specific city (let's say "San Francisco"), you can use the following code:

db.collection("users").where("addresses", "array-contains", { city: "San Francisco" })

This will return all user documents that have at least one address map with a "city" key that is equal to "San Francisco".

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-20 01:18:46 +0000

Seen: 10 times

Last updated: May 20 '23