[英]Firestore Cloud Function: Getting “ReferenceError: firebase is not defined”
I'm getting "ReferenceError: firebase is not defined" when running this firestore cloud function.运行此 Firestore 云 function 时,我收到“ReferenceError:firebase 未定义”。 I think the issue might be on the where clause but it looks defined since it's showing up on VSCode's IntelliSense.我认为问题可能出在 where 子句上,但它看起来已定义,因为它出现在 VSCode 的 IntelliSense 上。
const functions = require("firebase-functions");
const admin = require("firebase-admin");
var fetch = require("node-fetch");
admin.initializeApp();
const db = admin.firestore();
exports.sendPushNotifications = functions.firestore
.document("/messages/{chatId}/chats/{messageId}")
.onCreate(event => {
let message = "";
const members = event.get("members");
const text = event.get("text");
// const sender = event.get('user._id')
return db
.collection("users")
.where(firebase.firestore.FieldPath.documentId(), "==", members[1])
.get()
.then(users => {
users.docs.forEach(user => {
var expoToken = user.data().notificationToken;
if (expoToken) {
message = {
to: expoToken,
body: text
};
}
});
return Promise.all(message);
})
.then(message => {
return fetch("https://exp.host/--/api/v2/push/send", {
method: "POST",
headers: {
host: "exp.host",
accept: "application/json",
"accept-encoding": "gzip, deflate",
"content-type": "application/json"
},
body: JSON.stringify(message)
});
});
});
Change this:改变这个:
.where(firebase.firestore.FieldPath.documentId(), "==", members[1])
into this:进入这个:
.where(admin.firestore.FieldPath.documentId(), "==", members[1])
For reference, check the following:作为参考,请检查以下内容:
https://firebase.google.com/docs/reference/admin/node/admin.firestore https://firebase.google.com/docs/reference/admin/node/admin.firestore
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.