5

I'm trying to deploy a simple function on Firebase Cloud Functions but console logs an error that I can't figure out where is

My index.js:

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

exports.updateAccount = functions.firestore.document('accounts/{client_id}/movements').onWrite(change => {
    const document = change.after.exists ? change.after.data() : null
    console.log(document)
})

Console says:

⚠  functions: failed to create function updateAccount
HTTP Error: 400, The request has errors


Functions deploy had errors with the following functions:
        updateAccount


To try redeploying those functions, run:
    firebase deploy --only functions:updateAccount


To continue deploying other features (such as database), run:
    firebase deploy --except functions

Error: Functions did not deploy properly.
1
  • If you're having a problem with the Firebase CLI showing unexpected errors, you should reach out to Firebase support directly. firebase.google.com/support/contact Commented Jan 22, 2019 at 17:11

1 Answer 1

10

Your cloud function argument always points to the document level, not the collection level.

exports.updateAccount = functions.firestore
  .document('accounts/{client_id}/movements/{movement_id}')
  .onWrite(change => {
     const document = change.after.exists ? change.after.data() : null
     console.log(document)
})

You are trying to make the deployment in the collection level, not in the document level.

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

9 Comments

Hello, my path is something like, Users/{UserID}/username Users is collection, {UserID} is document and username is a field in the document. I am using a onCreate() trigger for the path mentioned above but getting the same error. I cannot use the path Users/{UserID}/ because username field may not be existing when {UserID} document is created. username takes a few seconds to get updated so I need to use onCreate() on the field.
why you are mentioning the field name in function deployment ? You don't want to mention the field name,instead you just mention to the document being created as wild card like Users/{UserID}.The UserID is the reference to the document being created
That's what I'm saying. Your answer worked. But username field may take upto 10 seconds to get into the document. The document {UserUID} gets created way to early that my username field. So if I use onCreate() on the document name itself. It returns undefined 🙁
Your point is the username field is taking some time to reflect back..?
Yes, thats taking time.The username field can take upto 10 seconds to update after the Dcoument is created. SO it returns undefined to me.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.