【发布时间】:2020-10-19 08:11:31
【问题描述】:
我有一个这样的 Firestore 集合:
假设我想通过更改文档“S4vfct....”的 address 和 cost 值来更新它。这是我的代码:
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();
}
}
});
代码成功更新了 address 的值,因为它是一个字符串。但不会改变 cost,因为它是一个 int。如何解决这个问题?
【问题讨论】:
标签: java android firebase google-cloud-firestore