我想在我的集合的所有文档中保存相同的字符串 [英] I want to save a same string in my all documents of a collection

查看:108
本文介绍了我想在我的集合的所有文档中保存相同的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这个应用程序中使用Firestore创建了一个应用程序我想在一次单击的所有文档中保存相同的字符串

I have created a application using Firestore in this app I want to save a same string in all documents of a collection in one click

例如:参见图片。我创建了一个集合名称 Links 。在这个集合中,我创建了许多文档。

For Example: See in the image. I have created a collection name Links. In this Collection I have created many Documents.

所以我想保存字符串字段:name value:anyname ,在按一下按钮的所有文件中。
怎么可能?请帮助。

So I want to save string field: name and value:anyname, in all documents in one click on press button. How it's possible? Please help.

推荐答案

为实现此目的,请使用以下代码:

To achieve this, please use the following code:

CollectionReference linksRef = rootRef.collection("Links");
linksRef.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
    @Override
    public void onComplete(@NonNull Task<QuerySnapshot> task) {
        if (task.isSuccessful()) {
            for (QueryDocumentSnapshot document : task.getResult()) {
                Map<String, Object> map = new HashMap<>();
                map.put("propertyName", "propertyValue");
                placesRef.document(document.getId()).update(map);
            }
        }
    }
});

所有文件现在都有一个新的 propertyName 将保存 propertyValue 的值的属性。

All your documents will have now a new propertyName property that will hold the value of propertyValue.

这篇关于我想在我的集合的所有文档中保存相同的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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