簡體   English   中英

如何在Android中將這種結構發送到Firebase Firestore?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM