I am trying to query my firestore database using cloud functions. I want to trigger an email notification every time a new reading in my database is under the value of 10.
Here is the relevant database structure for reference: database structure. The "readings" field is an array and each "reading" is a map which holds the fields "date" and "value".
Currently I am at the point where I can send an email notification every time a new user is created however I want this to work for the database. I am unsure how to query for the "readings" array and then for each individual reading.
Here is my code so far which sends an email when a new user is created
exports.sendNotification = functions.auth.user().onCreate((user) => { const mailOptions = { from: '"Spammy Corp." <[email protected]>', to:"[email protected]", text: "TEST" }; return mailTransport.sendMail(mailOptions) .then(() => console.log("It worked")) .catch((error) => console.error('There was an error while sending the email:', error)); });