首页 > 解决方案 > How to push values in existing array on firestore in nodeJs?

问题描述

I have this token schema over the firestore contains id and array of tokens

{ userId: "some String", "tokens": [ "token1", "token2" ] }

I need to push new tokens in tokens array where an Id matches with this schema userId

I am using this below code but not able to push values

    docRef.get().then(async function (doc) {
        if (!doc.empty) {
           let here1 = await db.collection("tokens").doc(doc.id);
            let here = doc.docs.update({
            deviceTokens: admin.firestore.FieldValue.arrayUnion(body.deviceToken)
            })

        }})

can someone explain what's the error here?

标签: node.jsmongodbfirebasegoogle-cloud-firestore

解决方案


推荐阅读