1. Are you ready for the Galaxy S20? Here is everything we know so far!

Firebase Cloud Functions - Detect Changes to List inside Document

Discussion in 'Android Development' started by TsubasaChronix, Jul 1, 2020.

  1. TsubasaChronix

    Thread Starter

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

    Code (Javascript):
    1. exports.sendNewLikeNotification = functions.firestore
    2.     .document('Uploads/{image_id}')
    3.     .onUpdate(event => {
    4.         const oldValue = event.before.data();
    5.         const newValue = event.after.data();
    6.  
    7.         const oldLikes = oldValue.likes
    8.         const newLikes = newValue.likes
    9.  
    10. /* Code that will comp[are like values */
    11.     });
    Am I headed in the right direction with this, or is there a better way of doing this? Will this path even work?
     



    1. Download the Forums for Android™ app!


      Download

       
Loading...
Similar Threads - Firebase Cloud Functions
  1. AsafKov
    Replies:
    0
    Views:
    353
  2. rowlanda38
    Replies:
    1
    Views:
    601
  3. Marcell Tanure
    Replies:
    0
    Views:
    707
  4. nurulaida
    Replies:
    0
    Views:
    583
  5. willy macharia
    Replies:
    0
    Views:
    830
  6. Macbeth Isack
    Replies:
    1
    Views:
    1,123
  7. Milo Williamson
    Replies:
    5
    Views:
    656
  8. Thiha Ko Ko
    Replies:
    0
    Views:
    1,177
  9. ibrmrt
    Replies:
    0
    Views:
    1,003
  10. Manish Thapa
    Replies:
    0
    Views:
    1,316

Share This Page

Loading...