删除Firestore中数组的索引

J. *_*Doe 7 firebase google-cloud-firestore

我在我的文档中得到了这些数据:

在此输入图像描述

我想删除索引0.我该怎么做?这应该是我想到的技巧:

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

但是errr打印为nil,没有删除任何内容.在获取文档时,我注意到使用此代码时数据有些奇怪:

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

打印出:

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

我看不出钥匙,它在哪里?如何在Firestore中删除索引处的内容?谢谢.

ran*_*ose 15

最后支持数组操作.现在通过值(而不是索引)支持删除,添加等:看到这个

目前,虽然我遇到了这个问题,但目前还有一些漏洞.

这里的开发博客:


Sam*_*ern 5

目前无法修改 Cloud Firestore 中存储的数组的单个元素。

如果您将数据存储为地图(键无关紧要),如下所示:

{
  name: "sam",
  things: {
    one: "value",
    two: "value"
  }
}
Run Code Online (Sandbox Code Playgroud)

然后你可以像这样删除单个元素:

// 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")
    }
}
Run Code Online (Sandbox Code Playgroud)

现在数据将如下所示:

{
  name: "sam",
  things: {
    two: "value"
  }
}
Run Code Online (Sandbox Code Playgroud)