I making firestore functions and I get this error in log
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;
});
I get this error because here I define the firebase in config
var defaultApp = admin.initializeApp(functions.config().firebase)
and not firestore, but into the web of firebase I create Firestore database. so I'm looking a way to connect my firestore to this file and work with firestore database