0

I'm trying to trigger a Firebase Cloud Function on a Realtime Database owned by a different app: the Hacker News API. I'm passing databaseUrl: https://hacker-news.firebaseio.com/ to admin.initializeApp(), and it deploys fine, but it never triggers, even though new items in this RTDB are regularly getting created.

const functions = require('firebase-functions')
const admin = require('firebase-admin')
admin.initializeApp({databaseUrl: 'https://hacker-news.firebaseio.com/'})

exports.itemUpdated = functions.database.ref('/v0/item/{id}').onCreate((snapshot, context) => {
      functions.logger.log('Item: ', context.params.id, snapshot.val())
      return null
})

I've tried it without databaseUrl in the local emulator, and it works fine. I've also tried a number of variations, eg functions.database.instance('hacker-news') and databaseUrl: 'https://hacker-news.firebaseio.com/v0', but no luck, it never triggers in production. Any idea what I'm missing?

ryan
  • 2,687
  • 1
  • 29
  • 38

1 Answers1

1

It's just not possible to write functions in one project for a database in another project. The events generated from database changes always stay within the project.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • Thanks for the answer! And, disappointing! Maybe consider raising an error in this case, ie when databaseUrl is in a different project, to avoid confusion? – ryan Aug 15 '22 at 01:39
  • 1
    I no longer work for Google. The best way to propose this is to post an issue on GitHub. https://github.com/firebase/firebase-functions – Doug Stevenson Aug 15 '22 at 01:45