Firestore:"add is not a function"

Firestore: "add is not a function"

我尝试在 Cloud Functions 中使用 Firestore,但遇到错误

db.collection(...).doc(...).collection(...).doc(...).add is not a function at Promise

我阅读了这些主题 , 和其他主题。但是 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
        });

我该如何解决?

doc是文档,add函数只对collection有效。要将数据写入文档,请使用 set 函数:

doc(matchID).set({ ... })