0

I am new to Firebase Realtime database but have been using Firestore for few months till now. I have written a below Cloud Function which tries to increment the access count of a particular record in the Realtime Database using ServerValue feature.But it crashed with Firebase logs

8:01:29.257 am incrCountByRTDB Function execution started
8:01:29.257 am incrCountByRTDB Billing account not configured. External network is not accessible and quotas are severely limited. Configure billing account to remove these restrictions
8:01:29.280 am incrCountByRTDB incrPersonAccessCountBy1
8:01:29.862 am incrCountByRTDB Function execution took 605 ms, finished with status: 'crash'

Code snippet

const admin = require('firebase-admin');
const functions = require('firebase-functions');

admin.initializeApp();

exports.incrCountByRTDB = functions.https.onRequest((req, res) => {
  console.log("incrPersonAccessCountBy1");
  admin.database().ref('Persons').child('mur_123').child('accessCount')
  .set(admin.database.ServerValue.increment(1))
  .then(function() {
    console.log('Increment succeeded');
    return res.status(200).send("Successfully incremented the accesscount");
  }).catch(function(error) {
    console.log('Increment failed', error);
    return res.status(200).send("Increment failed");
  })
});

exports.createPersonsCollection = functions.https.onRequest((req, res) => {
  admin.database().ref("Persons").child('mur_123').set({
    name: 'murali',
    accessCount: 0
}).then(function(){
  return res.status(200).send("Successfully created the persons collection");
}).catch(function (ex){
  console.log("Error", ex);
  return res.status(500).send("Creation failed");
})
});

Please let me know if I am missing something and help me resolve this.

Thanks Murali

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • The error is telling you that you need to enable billing to use these functionalities. You can check as well [this answer](https://stackoverflow.com/a/42787576/7757976) for more details. – llompalles Jul 06 '20 at 09:55
  • @llompalles, I have a billed account as well and it fails there as well. – Murali Kothandaraman Jul 06 '20 at 13:30

0 Answers0