when i want to update Cloud Firestore from Realtime Database i deployed bellow code and i get error.
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
const firestore = functions.firestore;
exports.onUserStatusChange = functions.database
.ref('/status/{userId}')
.onUpdate(event => {
var db = admin.firestore();
//const usersRef = firestore.document('/users/' + event.params.userId);
const usersRef = db.collection("users");
var snapShot = event.data;
return event.data.ref.once('value')
.then(statusSnap => snapShot.val())
.then(status => {
if (status === 'offline'){
usersRef
.doc(event.params.userId)
.set({
online: false,
last_active: Date.now()
}, {merge: true});
}
})
});
TypeError: Cannot read property 'ref' of undefined at exports.onUserStatusChange.functions.database.ref.onUpdate.event (/user_code/index.js:18:20) at cloudFunctionNewSignature (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:105:23) at cloudFunction (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:135:20) at /var/tmp/worker/worker.js:733:24 at process._tickDomainCallback (internal/process/next_tick.js:135:7)