简体   繁体   English

更新Firebase上所有子级的值

[英]Update value for all children on Firebase

I am trying to set the value of the "seen" key to true for all children. 我正在尝试将所有儿童的“ seen”键的值设置为true。

Is there a simple way to do this? 有没有简单的方法可以做到这一点?

Fetching all children to update each one individually seems like would be way overkill. 获取所有儿童以分别更新每个儿童似乎是一种过大的方式。

Thanks in advance for any help. 在此先感谢您的帮助。

在此处输入图片说明

There is no simple way to do this. 没有简单的方法可以做到这一点。 At the very least, you're going to have to get a hold of all the keys for all the children in order to be able to write into them. 至少,您将必须拥有所有孩子的所有键,以便能够对其进行写入。 With what you're showing now, the only way to do that is to fetch all the children so that you can construct references to them that can update each of their seen keys. 根据您现在显示的内容,唯一的方法就是获取所有子项,以便您可以构造对它们的引用,从而可以更新他们seen每个键。

Gather all the keys from all_notifications and create a dictionary where you you update all the seen keys to true. 收集all_notifications中的所有键,并创建一个字典,在其中您将所有可见的键更新为true。

Just do it with one call like so: 只需一个电话就可以做到:

ref.updateChildValues([key1: true, key2: true])

But it would make more sense to have another child under all_notifications where you store all the notification keys that are unseen. 但是,在all_notifications下有另一个子级存储您所有未显示的通知键会更有意义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM