I have a Firestore collection like this:
Let's say I want to update the document "S4vfct...." by changing its address and cost value. Here's my code:
FirebaseFirestore firestore = FirebaseFirestore.getInstance();
final CollectionReference colRef = firestore.collection("kontrakan);
colRef.whereEqualTo("owner", OWNER_NAME).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("address", edtAddress.getText().toString());
map.put("cost", edtCost.getText().toString());
colRef.document(document.getId()).set(map, SetOptions.merge());
Toast.makeText(getApplicationContext(), “Detail has been successfully updated.”, Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(getApplicationContext(), “Cannot update detail.”, Toast.LENGTH_SHORT).show();
}
}
});
The code successfully updates the value of address, since it's a String. But doesn't change cost, because it's an int. How to fix this?