我制作firestore函数,我在日志
中收到此错误 import * as functions from 'firebase-functions'
import * as admin from 'firebase-admin'
var defaultApp = admin.initializeApp(functions.config().firebase)
const firestore = admin.firestore();
const firebase = admin.database();
module.exports.onUserStatusChange = functions.firestore.document('/status/{userId}').onUpdate((change,context) => {
const newValue = change.after.data();
console.log('new value',newValue);
console.log('change',change);
console.info('context',context)
admin.firestore().collection('status')
.where('state', '==', 'online')
.onSnapshot(function(snapshot) {
snapshot.docChanges.forEach(function(change) {
console.info('change->',change.type)
if (change.type === 'added') {
var msg = 'User ' + change.doc.id + ' is online.';
console.log(msg);
// ...
}
if (change.type === 'removed') {
var msg = 'User ' + change.doc.id + ' is offline.';
console.log('removed',msg);
// ...
}
});
});
return newValue;
});
我收到此错误,因为我在配置
中定义了firebase var defaultApp = admin.initializeApp(functions.config().firebase)
而不是firestore, 但是进入firebase网络我创建了Firestore数据库。 所以我正在寻找一种方法将我的firestore连接到这个文件并使用firestore数据库
答案 0 :(得分:3)
改变这个:
var defaultApp = admin.initializeApp(functions.config().firebase)
到此:
var defaultApp = admin.initializeApp();
更多信息: