How to request documents containing sent parameter in Firestore?

I am using the new Cloud Firestore in Android. So I ran into this problem in firestore. I want to request a document containing an identifier in its array fields.

for example, I have a document with a field in firestore containing an array of integers, for example: image1

Therefore, when I have the identifier 66940, I can get the document and other documents containing the identifier, without returning other documents that do not contain the identifier 66940.


Besides this approach, I can also use id (66940) to search for it in the document id. The format of my documents is as follows:
- 66940_88123
- 12323_66940

The idea is to return documents containing 66940 in their identifier. I read about the solution here , but I really don't understand how to implement it.

+5
source share
1 answer

This is a general question, so we posted some documentation on how to work with arrays in Cloud Firestore: https://firebase.google.com/docs/firestore/solutions/arrays

In short, if you want to request membership in an array, it is better to store your data as a boolean map.

So instead:

{ name: "sam", userGgIds: [12345, 67890] } 

Do you want to:

 { name: "sam", userGgIds: { 12345: true, 67890: true } } 

You can then run this query to search for documents containing the identifier "12345"

 db.collection("users").where("userGgIds.12345", "==", true).get() 
+5
source

Source: https://habr.com/ru/post/1272526/


All Articles