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

前端 未结 1 567
情书的邮戳
情书的邮戳 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<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);
                }
            }
        }
    });
    

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

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