I want to save a same string in my all documents of a collection

前端 未结 1 582
情书的邮戳
情书的邮戳 2021-01-25 14:02

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

For Example: See in the image. I hav

1条回答
  •  渐次进展
    2021-01-25 14:20

    To achieve this, please use the following code:

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

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

    0 讨论(0)
提交回复
热议问题