Delete index at array in Firestore

后端 未结 3 608
臣服心动
臣服心动 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:24

    export const deleteArrayIndex = (collectionName, id, index) => {
        db.collection(collectionName).doc(id).update(
            { [index]: firebase.firestore.FieldValue.delete() }
        ).then(function () {
            console.log(index + "  is deleted");
        }).catch(function (error) {
            console.error("Error removing document: ", error);
        });
    }
    

提交回复
热议问题