2023-07-09
-
I would like to aggregate Firestore data for ChatGPT for middle and high school students.
I tried to read the data, but couldnāt.
- I did
db.collection('users').get()
but snapshot.size is zero - I asked what caused it.
- Several causes were mentioned, check from above.
- I thought the rules were wrong.ā I was told, so I put up the rules and asked him to check them.
I couldnāt read the rules after I changed them.
- I created the code to get one specific message, and it was done.
- But
db.collection('users').get()
but snapshot.size is zero
Thinking again, I realized, āEven if I grant service accounts the same access rights as normal users, I canāt get a list of users.
- snapshot.size is zero. I just noticed that the rule deny traversal. Fix it
allow list: if request.auth.token.firebase.sign_in_provider == "null";
Still no luck, I asked why the phenomenon of being able to get the terminal object but not being able to traverse the parent occurs.
- No user document: When you fetch a nested sub-collection document directly (as in code A), Firestore doesnāt need the parent document to exist. In other words, even if thereās no document at users/{userId}, you can still fetch a document at users/{userId}/rooms/{roomId}/messages/{messageId}.
- HF8NVT*MTY4ODgyODA1My4xNi4xLjE2ODg4MzM2NDguMC4wLjA.#non-existent_ancestor_documents Managing Cloud Firestore in Firebase console
-
A document can exist even if the ancestor does not exist.
- Thisā¦
How do I enumerate descendant documents when no ancestor document exists?
- How to get all
/users/<user_id>/rooms/<room_id>
when/users/<user_id>
is not exists. - There is a way to fetch all rooms from all users using a Firestore feature called Collection Group Queries.
db.collectionGroup('rooms').get()
- Itās done.
How do you know which user the room belongs to?
- Given doc, how can I see its parent <user_id>
-
doc.ref.parent.parent.id
All thatās left is to tally the totals! And then itās over!
This page is auto-translated from /nishio/Firestoreć®ćć¼ćæćéčØććć using DeepL. If you looks something interesting but the auto-translated English is not good enough to understand it, feel free to let me know at @nishio_en. Iām very happy to spread my thought to non-Japanese readers.