2017-10-04 64 views
0

我已經在測試新的Firestore API,並且在處理文檔和調用update時遇到了一些問題。Firestore數據庫:更新丟失的文檔

我試圖更新一個沒有現有文件,我收到一個錯誤。顯然這沒問題,因爲文檔說如果DocumentReference不存在,update調用將會失敗。然而,讀official documentation我看到的一個代碼塊:

// Update the population, creating the document if it 
// does not already exist. 
db.collection("cities").document("Beijing").update(
     new UpdateOptions().createIfMissing(), 
     "population", 
     21500000); 

我試圖複製,但我沒有找到UpdateOptions電話。此外,檢查update的不同覆蓋方法,這些調用不是構造函數。

我使用的是Firebase的11.4.2版本。有什麼想法發生了什麼?

非常感謝你提前。

回答

3

Firestore API在測試版發佈之前發生變化,UpdateOptions不再存在。如果您想合併域插入到文檔中,可能會或可能不存在使用set,就像這樣:

Map<String, Object> data = new HashMap<>(); 
data.put("population", 21500000); 

db.collection("cities").document("Beijing") 
    .set(data, SetOptions.merge()); 

不幸的是,我們的翻譯文檔目前已經過時,請參閱英文版本現在。