2023-07-09

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.

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.

  • nishio.iconsnapshot.size is zero. I just noticed that the rule deny traversal. Fix it
  • GPT-4.iconallow 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.

How do I enumerate descendant documents when no ancestor document exists?

  • nishio.icon How to get all /users/<user_id>/rooms/<room_id> when /users/<user_id> is not exists.
  • gpt-4.icon 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?

  • nishio.iconGiven doc, how can I see its parent <user_id>
  • gpt-4.icon 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.