Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
firebase-将特定字段设置为专用字段_Firebase_Google Cloud Firestore_Firebase Security - Fatal编程技术网

firebase-将特定字段设置为专用字段

firebase-将特定字段设置为专用字段,firebase,google-cloud-firestore,firebase-security,Firebase,Google Cloud Firestore,Firebase Security,我想在我的用户配置文件中将某些字段设置为私有。我有一个带有姓名、电子邮件等的用户文档,但我想让黄金字段只读,因为我计划在用户进行应用内购买时使用云函数更新此值。我以前没有做过应用内购买,所以这是我能想到的唯一方法 我知道在使用Firestore安全规则时,我可以在路径中使用通配符变量,但据我所知,我只能使用通配符变量来代替文档和集合。您是正确的,Wildard只能用于标识集合和文档,而不能用于标识字段。但是,您可以选择创建一个额外的“私人收藏”,您可以使用标准安全规则对其进行保护。例如— 使用

我想在我的用户配置文件中将某些字段设置为私有。我有一个带有姓名、电子邮件等的用户文档,但我想让黄金字段只读,因为我计划在用户进行应用内购买时使用云函数更新此值。我以前没有做过应用内购买,所以这是我能想到的唯一方法


我知道在使用Firestore安全规则时,我可以在路径中使用通配符变量,但据我所知,我只能使用通配符变量来代替文档和集合。

您是正确的,Wildard只能用于标识集合和文档,而不能用于标识字段。但是,您可以选择创建一个额外的“私人收藏”,您可以使用标准安全规则对其进行保护。例如—

  • 使用者

    • 用户1
      • 电子邮件
      • 名字
  • 黄金

    • 用户1
      • 黄金价值
那么在你的安全系统里-

service cloud.firestore {
  match /databases/{database}/documents {
    match /gold/{userId} {
      allow read, update, delete: if request.auth.uid == userId
      allow create: if request.auth.uid != null;
    }
    match /users/{document=**} {
      allow read;
      allow write: if request.auth.uid != null;
    }
  }
}

您是对的,wildards只能用于标识集合和文档,而不能用于标识字段。但是,您可以选择创建一个额外的“私人收藏”,您可以使用标准安全规则对其进行保护。例如—

  • 使用者

    • 用户1
      • 电子邮件
      • 名字
  • 黄金

    • 用户1
      • 黄金价值
那么在你的安全系统里-

service cloud.firestore {
  match /databases/{database}/documents {
    match /gold/{userId} {
      allow read, update, delete: if request.auth.uid == userId
      allow create: if request.auth.uid != null;
    }
    match /users/{document=**} {
      allow read;
      allow write: if request.auth.uid != null;
    }
  }
}

谢谢Chris,这看起来是我需要实施的解决方案谢谢Chris,这看起来是我需要实施的解决方案