0

So in my firebase app, I want to access an array whenever the data source is updated.

This part of app works well. The variables are assigned successfully.

exports.sendUsersNotification = functions.database.ref('/Groups/{groupId}/messageList/{messageId}/')
.onWrite(event => {
  const original = event.data.val();
  let userId = original['userId']
  let groupId = event.params.groupId;
  let messageId = event.params.messageId;

  const payload = {
    notification: {
      title: 'Messenger',
      body: 'You have a new message'
    }
  };



});

The array I want to access and loop through is in 'Groups/{groupId}/listeners'.

How can I access it?

0

1 Answer 1

1

Cloud Functions database triggers will only give you the data at the location in the database that matches the pattern you gave in functions.database.ref(). You can use the Admin SDK to query the database at other locations, or you can use event.data.ref.root to build a Reference to other locations, and use once() to perform the query. There are a lot of examples of this in documentation and samples.

Sign up to request clarification or add additional context in comments.

1 Comment

@BobSnyder That's right, I made a mistake, will correct. No one should be using on() in a function, really.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.