Javascript Firestore安全规则错误:FirebaseError:缺少权限或权限不足

Javascript Firestore安全规则错误:FirebaseError:缺少权限或权限不足,javascript,firebase,google-cloud-firestore,firebase-security,Javascript,Firebase,Google Cloud Firestore,Firebase Security,预期行为 目标是修改我的安全规则,这样只有经过身份验证的用户才能读写该特定用户的数据。这是基于用户UID,这是我们识别单个用户的方式(这是通过firebase身份验证完成的,所以不确定问题出在哪里) 我的数据库结构 我的安全规则是 service cloud.firestore { match /users/{userId} { allow read: if request.auth.uid == userId; } } 错误 FirebaseError:缺少或权限不足 任何关

预期行为

目标是修改我的安全规则,这样只有经过身份验证的用户才能读写该特定用户的数据。这是基于用户UID,这是我们识别单个用户的方式(这是通过firebase身份验证完成的,所以不确定问题出在哪里)

我的数据库结构

我的安全规则是

service cloud.firestore {
  match /users/{userId} {
   allow read: if request.auth.uid == userId;
  }
}
错误

FirebaseError:缺少或权限不足

任何关于我能在这里做什么的建议都将不胜感激。我还没有找到任何适用于其他问题的答案

我的查询

fbDB.collection('users').doc(user.uid).collection('practitionerClients').doc(trackingClientNameCheck).collection("sessions").doc(trackingClientNameCheck + currentTime).set({

    name: trackingClientName,
    timeOfSession: currentTime,
    vocValues: vocValueSaved,
    sudsValues: sudsValueSaved, 
    recallValues: recallValueSaved,
    moodValues: moodValueSaved,
    clientNotes: trackingClientNotes,
    triggeringEventProcessed: trackingTriggeringEvent,
    positiveBelief: trackingPositiveBelief,
    negativeBelief: trackingNegativeBelief

}).then(function() {
    console.log("Document successfully written!");

})

.catch(function(error) {
    console.error("Error writing document: ", error);
});;
*我的错误


您的规则与任何文档都不匹配。您必须保留在初始规则集中提供的
/databases/{database}/documents
的匹配项,如中所示


您需要在规则中指定该子集合

service cloud.firestore {
  match /databases/{database}/documents {

    match /users/{userId} {
      allow read: if request.auth.uid == userId;

      match /practitionerClients/{clientId} {
        allow read: if request.auth.uid == userId;
      }

    }
  }
}
无论何时添加这样的新子集合,通常都必须指定它或为该路径添加通配符规则。所以你可以这样做,而不是按照上面的规则

service cloud.firestore {
  match /databases/{database}/documents {

    match /users/{userId}/{document=**} {
      allow read: if request.auth.uid == userId;
    }
  }
}

发布有关安全规则的帖子时,您可以阅读更多内容

,您的问题还应包含被拒绝的客户端的代码。我们需要能够看到您的规则与您的查询匹配。嘿!感谢您的回复:)我仍然收到一个错误-以下是注册new.js:2740错误写入文档:FirebaseError:缺少或权限不足。在新t()在lr。)在qt()在lr.c.DispatchEvent请编辑问题,以包括所有相关细节-不要在评论中留下它们,因为它们很难阅读。正如我在其他评论中所说的,您应该包括显示您试图进行的查询的源代码。您的代码试图查询子集合中的文档。您还需要编写与该子集合匹配的规则。用户标识通配符不递归匹配。我强烈建议阅读文档,了解规则是如何工作的。
service cloud.firestore {
  match /databases/{database}/documents {

    match /users/{userId} {
      allow read: if request.auth.uid == userId;

      match /practitionerClients/{clientId} {
        allow read: if request.auth.uid == userId;
      }

    }
  }
}
service cloud.firestore {
  match /databases/{database}/documents {

    match /users/{userId}/{document=**} {
      allow read: if request.auth.uid == userId;
    }
  }
}