I iterate throught all the users node, I just want to send notifications to the users who have shop as a value inside the document, if there is users that dont have this attribute inside the document I dont want to send them a notification
exports.rememberToOpenStore = functions.pubsub.schedule('30 09 * * *').onRun(async (context) => {
var db = admin.firestore();
let snap = await db.collection('user').get();
return snap.forEach((doc) => {
if(doc.data().shop !== null){
const deviceToken = doc.data().deviceToken
const payload = {
notification: {
title: "Good morning ! ",
body: "Remember to open your store."
}
}
return admin.messaging().sendToDevice(deviceToken,payload)
}
return null;
});
});
I want to know if this
if(doc.data().shop !== null)
will do the trick to know which user has or not that attribute
Is there a better way to do this with a where query with something like
let snap = await db.collection('user').where("shop" "!=", null).get();
to just get users that have that shop value inside the document ?
I want to do it that way to save reads