![](/img/trans.png)
[英]Firebase Firestore on Android (Java): How much and what kind of requests are here?
[英]How to make this kind of structure in android to be sent to firebase firestore?
我正在使用這種結構
public class NewVendor
{
public String title;
public Map<String,String> array;
public NewVendor(String title, Map<String, String> array) {
this.title = title;
this.array = array;
}
}
Map<String,String> list = new HashMap<>();
list.put("Vendor Name",newVendorName);
list.put("Vendor Address",newVendorAddress);
NewVendor newVendor = new NewVendor(newVendorName,list);
db.collection("Bills").document(firebaseUser.getUid()).set(newVendor)
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid)
{
Toast.makeText(AddNewBillActivity.this, "Success", Toast.LENGTH_SHORT).show();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(AddNewBillActivity.this, "Failure", Toast.LENGTH_SHORT).show();
}
但是它不起作用,它覆蓋了最后保存的數據,但是我想添加最新的對象。 Firestore中不允許使用ArrayList。
您要更新現有文檔,因此應調用update
。 這要求您指定要更新文檔的哪些字段,在這種情況下,請指定newVendorName
:
Map<String,Object> updates = new HashMap<>();
updates.put(newVendorName, newVendor);
db.collection("Bills").document(firebaseUser.getUid()).update(updates)...
有關更多信息,請閱讀有關更新嵌套對象中字段的Firestore文檔 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.