如何将用户创建的集合 updating/deleting 锁定到在 firestore 中创建集合的同一用户(不使用云函数)?

How to lock updating/deleting a collection created by a user to the same user who created the collection in firestore (without using cloud Functions)?

我有以下模型和规则...等式的第一部分工作正常用户可以 CRUD 他自己创建的集合,并且它与创建者具有相同的 ID。

问题在于该用户创建的另一个集合,因为它具有不同的 ID(firestore 自动生成的 ID,我想将此集合锁定为仅由创建它的用户修改)不知道如何要做到这一点?

Collections Model

// Data   // doc id === uid
subDataId: null,
createdAt: Timestamp.now(),
            
// Sub Data // doc id === generated automatically by fb refrenced in the data collection. 
online: false,
createdAt: Timestamp.now(),

// Firebase rules 

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {

    match /Data/{userId} {
    allow read , create: if request.auth != null
    allow update, delete : if request.auth.uid == userId
    }
    
    match /SubData/{SubDataId} {
        allow read , create: if request.auth != null
       //  allow update : if request.auth.uid == ?????????
 
    }
  }
}

编写一个规则,要求用户提供他们自己的用户 ID 作为正在创建的文档的一个字段(参见 documentation about requiring that a field is provided)。确保您的应用程序中的代码完全符合要求。还要编写一个规则,检查更新文档的用户的用户 ID 是否也与该用户之前写入的字段相匹配。

您可能也想