有没有一种方法可以使用Firestore安全规则使用FieldValue.increment()更新文档字段?

时间:2019-04-20 08:01:17

标签: google-cloud-firestore firebase-security-rules

我刚刚开始使用像Firestore这样的noSQL数据库,并想在使用Firestore安全规则在第二个集合中创建文档后,如何从一个集合中查找无损的文档字段。

js代码

collection('some_collections').add({name: 'name', anotherId: 'abc' })
 .then(() => {
   collection.('another_collections').doc('abc')
   .update({counter: FieldValue.increament(1) });
});

安全规则中的类似内容

function isIncremented() {
      get(/databases/$(database)/documents/another_collections
      /$(request.resource.data.anotherId)).counter = FieldValue.increament(1);
      return true;
    }

 match /some_collections/{some_collectionId} {
        allow create: if signedIn() && isIncremented();
}

1 个答案:

答案 0 :(得分:0)

不可能使用安全规则来修改数据库中的任何数据。

如果您需要在更改另一个文档时自动对文档进行更改,则应查看Cloud Functions来设置在文档更改后执行的触发器。