• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Firebase Cloud Functions - Detect Changes to List inside Document

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).

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?
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones