Skip to content Skip to sidebar Skip to footer

I Want To Save A Same String In My All Documents Of A Collection

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 have created a

Solution 1:

To achieve this, please use the following code:

CollectionReference linksRef = rootRef.collection("Links");
linksRef.get().addOnCompleteListener(newOnCompleteListener<QuerySnapshot>() {
    @OverridepublicvoidonComplete(@NonNull Task<QuerySnapshot> task) {
        if (task.isSuccessful()) {
            for (QueryDocumentSnapshotdocument : task.getResult()) {
                Map<String, Object> map = newHashMap<>();
                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.

Post a Comment for "I Want To Save A Same String In My All Documents Of A Collection"