I am trying to query another collection inside my firestore Cloud Function trigger event but it always return nothing, But when i tried querying inside that firestore trigger event it works
take a look
exports.newTicketNotification = functions.firestore
.document('tickets/{refNo}')
.onCreate(async (snap, context) => {
//get user
const user = snap.data().ticketOwnerUid
// Here i tried to query a collection called fcmTokens(Where my fcmTokens are stored)
// this returned no matching documents
// but if i use this db.collection('tickets').where('tickeOwnerUid', '==', user).get() it works
db.collection('fcmTokens').where('userUid', '==', user).get()
.then(snapshot => {
if (snapshot.empty) {
console.log('No matching documents.');
return;
}
snapshot.forEach(doc => {
console.log(doc.id, '=>', doc.data());
});
})
.catch(err => {
console.log('Error getting documents', err);
});
});
I am using this so i can get the fcm token of the device and send a notification to them. is this the right way to do it? or you guys can recommend a better way Thank you in advance ;) Ps. I'm stuck for 2 days :(
dbvariable? - Renaud Tarnec