TsubasaChronix
Lurker
I have tried searching around to find how to best do this in Firestore (I am new to nosql/non relational databases). I recently discovered Cloud Functions as a way to send notifications to users of my app when changes have been made to a document in the database. That part is very clear, however I am not able to see the best way to do this for lists that are stored inside that document. Currently my structure has an Image document that was added to the Uploads collection. Each Image has it's own document ID of course. I am trying to send a notification when a new like has been added. My Cloud Function below is attempting to grab the old like list and compare it to the new like list to determine the new value (Or if any changes made at all).
Am I headed in the right direction with this, or is there a better way of doing this? Will this path even work?
JavaScript:
exports.sendNewLikeNotification = functions.firestore
.document('Uploads/{image_id}')
.onUpdate(event => {
const oldValue = event.before.data();
const newValue = event.after.data();
const oldLikes = oldValue.likes
const newLikes = newValue.likes
/* Code that will comp[are like values */
});
Am I headed in the right direction with this, or is there a better way of doing this? Will this path even work?