Firestore:“添加不是功能”

问题描述 投票:4回答:1

我尝试在云功能中使用Firestore,但我遇到了错误

db.collection(...)。doc(...)。collection(...)。doc(...)。add不是Promise的函数

我读了这些主题firstsecond等。但是id并没有帮助我。 package.json看起来

"firebase": "^4.3.1",
"firebase-admin": "^5.5.1",
"firebase-functions": "^0.7.5",

云功能之一

const admin = require('firebase-admin');
var db = admin.firestore();

这个代码来自函数

const currentUserMatchProm = db.collection('userMatches').doc(currentUserID).collection('test').doc(matchID).add({
            'matchID': matchID,
            'matchedUserID': eventUserID,
            'timestamp': timestamp,
            'isActive': false
        });

        const eventUserMatchProm = db.collection('userMatches').doc(eventUserID).collection('test').doc(matchID).add({
            'matchID': matchID,
            'matchedUserID': currentUserID,
            'timestamp': timestamp,
            'isActive': false
        });

我该如何解决?

node.js firebase google-cloud-firestore firebase-admin
1个回答
12
投票

doc是文件,add功能仅供收藏。要将数据写入文档,请使用set函数:

doc(matchID).set({ ... })
© www.soinside.com 2019 - 2024. All rights reserved.