在firebase中检索文档

在firebase中检索文档,firebase,google-cloud-datastore,firebase-security,Firebase,Google Cloud Datastore,Firebase Security,我在firebase有一个数据库,我想检索一个我知道其名称的特定文档(称为documentA),并且我在服务器上有一个工作规则 我怎样才能得到一份符合安全规则的文件?我正在尝试:val docRef=db.collection(“cities”).document(“SF”).get(),但我不知道如何包含用户身份验证 数据库的结构如下 cars | |-documentA |-documentB |-documentC 安全规则: rules_version = '2'; service c

我在firebase有一个数据库,我想检索一个我知道其名称的特定文档(称为documentA),并且我在服务器上有一个工作规则

我怎样才能得到一份符合安全规则的文件?我正在尝试:
val docRef=db.collection(“cities”).document(“SF”).get()
,但我不知道如何包含用户身份验证

数据库的结构如下

cars
|
|-documentA
|-documentB
|-documentC
安全规则:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /cars/{carId}  {
      allow read, write: if request.auth.uid == resource.data.userId;
      allow create: if request.auth.uid != null;
    }
  }
}

Firebase用户身份验证自动包含在已登录的用户中。除了将代码写入登录用户之外,您无法编写任何代码来手动添加身份验证。如果您的安全规则需要经过身份验证的用户,则必须在进行查询之前安排登录