0

I'm trying to deploy the two following functions:

exports.increaseWaitinglistCounters = functions.database
  .ref('waitinglists/$iid/$uid')
  .onCreate(async () => {
    await admin
      .database()
      .ref(`waitinglistCounters/$iid`)
      .transaction((count) => {
        return (count || 0) + 1;
      });
  });

exports.decreaseWaitinglistCounters = functions.database
  .ref('waitinglists/$iid/$uid')
  .onDelete(async () => {
    await admin
      .database()
      .ref(`waitinglistCounters/$iid`)
      .transaction((count) => {
        return Math.max((count || 0) - 1, 0);
      });
  });

But I keep hitting deployment errors, I looked in the Google Cloud logs but I can't find anything useful.

{
  "protoPayload": {
    "@type": "type.googleapis.com/google.cloud.audit.AuditLog",
    "status": {
      "code": 13,
      "message": "Failed to configure trigger providers/google.firebase.database/eventTypes/[email protected] (__gcf__.us-central1.decreaseWaitinglistCounters)"
    },
    "authenticationInfo": {
      "principalEmail": "[email protected]"
    },
    "serviceName": "cloudfunctions.googleapis.com",
    "methodName": "google.cloud.functions.v1.CloudFunctionsService.CreateFunction",
    "resourceName": "projects/xxxxxx/locations/us-central1/functions/decreaseWaitinglistCounters"
  },
  "insertId": "ilglgod1bk8",
  "resource": {
    "type": "cloud_function",
    "labels": {
      "project_id": "xxxxxx",
      "region": "us-central1",
      "function_name": "decreaseWaitinglistCounters"
    }
  },
  "timestamp": "2021-02-04T16:10:10.853578Z",
  "severity": "ERROR",
  "logName": "projects/xxxxxxx/logs/cloudaudit.googleapis.com%2Factivity",
  "operation": {
    "id": "operations/xxxxxx",
    "producer": "cloudfunctions.googleapis.com",
    "last": true
  },
  "receiveTimestamp": "2021-02-04T16:10:11.326391635Z"
}

What's wrong with my code? I'm trying to increment and decrement a counter when a node is created or removed from a parent node.

2
  • Could you please display your deployment errors? Commented Feb 4, 2021 at 16:35
  • @LouisCoulet added Commented Feb 4, 2021 at 16:38

1 Answer 1

2

The error log mentions an issue with your second function's trigger, I think you should replace the dollar sign with curly braces in your ref definition for wildcards:

ref('waitinglists/{iid}/{uid}')

The related documentation: https://firebase.google.com/docs/functions/database-events#specify_the_instance_and_path

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.