2017-10-13 127 views
2

我得到了我的文檔中這樣的數據:在陣列刪除指數公司的FireStore

enter image description here

我想刪除索引0我​​該怎麼辦呢?這應該做的伎倆,我想:

db.collection("data").document("free").updateData(["deleteme.deletemee.0" : FieldValue.delete()]) { (errr) in 
     print(errr) 
    } 

但errr打印零,並沒有被刪除。

db.collection("data").document("free").getDocument { (doc, err) in 
     guard let _doc = doc, 
      doc?.exists ?? false else{ return } 
     print(_doc.data()) 
    } 

此打印出:

["deleteme": { 
    deletemee =  (
     1 //this is the value for the key, but where is my key?! :(
    ); 
}] 

我看不到鑰匙,哪裏是什麼時候得到的文件我用這個代碼時發現了一些奇怪的數據?如何在Firestore的索引處刪除某些內容?謝謝。

回答

1

目前無法修改存儲在Cloud Firestore中的陣列的各個元素。

如果存儲的數據的映射(鍵不沒關係)這樣的:

{ 
    name: "sam", 
    things: { 
    one: "value", 
    two: "value" 
    } 
} 

然後你就可以刪除單個元素這樣的:

// Delete the things.one data 
db.collection("whatever").document("whatever").updateData([ 
    "things.one": FieldValue.delete(), 
]) { err in 
    if let err = err { 
     print("Error updating document: \(err)") 
    } else { 
     print("Document successfully updated") 
    } 
} 

現在的數據看起來像這個:

{ 
    name: "sam", 
    things: { 
    two: "value" 
    } 
} 
+0

> :(嗯好吧,所以陣列是非常無用的,因爲他們不能改變... –

+0

是r現在它們並不是非常有用,但這些僅僅是Beta限制,將來我們會更好地支持數組/數組查詢。 –

+0

不能等:)謝謝 –