I am trying to update a field of existing document in my collection in FireBase Firestore. I want to search that document using one of its field. My collec
To solve this, please use the following lines of code:
FirebaseFirestore rootRef = FirebaseFirestore.getInstance();
CollectionReference complaintsRef = rootRef.collection("complaints");
complaintsRef.whereEqualTo("id", 5).get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.isSuccessful()) {
for (QueryDocumentSnapshot document : task.getResult()) {
Map<Object, String> map = new HashMap<>();
map.put("complainant_Name", "ABC");
complaintsRef.document(document.getId()).set(map, SetOptions.merge());
}
}
}
});
After using this code, the property complainant_Name
will hold the value of ABC
.