Delete index at array in Firestore

后端 未结 3 600
臣服心动
臣服心动 2020-11-30 14:15

I got this data in my document:

I want to delete index 0. How do I do this? This should do the trick I thought:

    db.collection(\"data\").         


        
3条回答
  •  一整个雨季
    2020-11-30 14:22

    It is not currently possible to modify individual elements of an array stored in Cloud Firestore.

    If you stored the data as a map (the keys dont matter) like this:

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

    Then you can delete individual elements like this:

    // 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")
        }
    }
    

    Now the data will look like this:

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

提交回复
热议问题