创建新用户后,我想将数据添加到FireStore中的新集合中。
我有自己的职能设置;
exports.createUser = functions.firestore.document('Users/{userId}')
.onCreate((snap, context) => {
const newValue = snap.data();
if (snap.data() === null) return null;
const userRef = context.params.userId
console.log("create user found " + (userRef))
let notificationCollectionRef = firestoreDB.collection('Users').document(userRef).collection('Notifications')
let notificationDocumentRef = notificationCollectionRef.document('first notification')
return notificationDocumentRef.set({
notifications: "here is the notificiation"
}, {merge: true});
});
当运行这个函数时,我得到了控制台日志,正确地打印出了用户ID,但是我得到了以下错误;
类型错误:firestoredb.collection(…).document不是函数。
在exports.createuser.functions.firestore.document.oncreate上(/user_code/index.js:23:73)
在对象处。(/user_code/node_modules/firebase函数/lib/cloud函数.js:112:27)
下一个(本机)
at/user_code/node_modules/firebase functions/lib/cloud functions.js:28:71
at_uuu等待程序(/user_code/node_modules/firebase functions/lib/cloud functions.js:24:12)
at cloudfunction(/user_code/node_modules/firebase functions/lib/cloud functions.js:82:36)
AT/var/tmp/worker/worker.js:728:24
at process.TickDomainCallback(内部/process/next_Tick.js:135:7)
我不熟悉JS&函数。一如既往,任何帮助都非常感谢。