Firestore安全规则中的更新字段数 [英] Number of update fields in firestore security rules

查看:63
本文介绍了Firestore安全规则中的更新字段数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从客户端进行批处理操作,以仅更新一个字段,但是在进行批处理操作并在安全性规则中进行测试时,发现正在更新多个字段.我使用request.resource.data.size() >1request.resource.data.keys().size()>1并返回了true(正在更新文档)进行了检查,但这并不是我想要检查的安全规则,即使用诸如request.resource.data.keys().hasOnly(['someFieldToUpdate'])之类的检查仅更新了一个字段,但这不是现在可以工作了,以前我记得有writeFields可以检查,但是现在在文档中不存在,并且答案提到它.那么,如何在批处理操作中检查实际上正在更新的字段?

I am making batch operation from client to update only one field but while making batch operation and on testing in security rules It is observed that more than one fields are being updated. I checked this using request.resource.data.size() >1 and request.resource.data.keys().size()>1 returning true(document being updated) but this is not intended as I want to check in security rules that only one field is being updated using checks like request.resource.data.keys().hasOnly(['someFieldToUpdate']) but this is not working now, previously I remember there was writeFields to check that but it is not present now in documentation and also this answer mentions it. So how can I check the fields which are actually being updated in batch operations now ?

推荐答案

request.resource.data字段包含资源,因为在写操作成功之后该资源将存在. writeFields属性已删除,因为无法始终可靠地填充它.

The request.resource.data field contains the resource as it will exist after the write operation has succeeded. The writeFields property was removed since it could not always reliably be populated.

现在,我唯一想到的选择是检查每个字段是否都已更改,然后仅在有一个更改的情况下才允许更改.但老实说,这听起来像是一个奇怪的用例.我看到一个更常见的用例是限制用户可以更新的哪些特定字段,而不是一次可以更新多少.

Right now the only option I can think of is to check if each individual field has changed, and then only allow it if there's one change. But to be honest, that sounds like an odd use-case. A more common use-case I see it to limit what specific fields the user can update, not how many they can update at once.

这篇关于Firestore安全规则中的更新字段数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆