问题
I created a Collection of user IDs for each user and I want to set the database rules to read the collection item only if the user ID matches the collection item name. I tried something like:
 service cloud.firestore {
    match /databases/{database}/documents {
      match /{document=**} {
        allow read: if request.auth != null;
      }
      match /{userId} {
        allow read: if belongsTo(userId);
      }
      function belongsTo(userId) {
        return request.auth.uid == userId
      }
    }
    }
回答1:
Firestore reads documents. There is no concept of reading a collection. So your rules must provide access to documents.
To grant access to all documents in the collection named after the user's UID:
  match /{userId}/{document} {
    allow read: if belongsTo(userId);
  }
来源:https://stackoverflow.com/questions/55991827/how-to-read-collection-only-if-uid-matches-collection-name-in-firebase-firestore