0
votes

Relatively new to using typescript let alone Visual Studio. I'm trying to get the after, before, and timestamp after an onWrite is triggered but it doesn't deploy with the error being on helloWorld function. I used the guide that is on the Firebase YT channel and the hello world triggered by http worked properly.

I'm sure it's obvious but anyone care to help D:?

import * as functions from 'firebase-functions';

// // Start writing Firebase Functions
// // https://firebase.google.com/docs/functions/typescript
//
export const helloWorld = 
functions.firestore.document("TestDoc").onWrite ((change, context) => {
    console.log(change.after)
    console.log(change.before)
    console.log(context.timestamp)
});

Error: HTTP Error: 400, The request has errors

Functions deploy had errors with the following functions: helloWorld

1
Please edit your question to include the exact error message, the line that the message appears on, and the stack trace. - Frank van Puffelen
@FrankvanPuffelen included the error message and where it told me the error was. Will update with stacktrace soon - insta catering

1 Answers

0
votes

The value you provide in .document() must properly point to a Firestore document. This means that simply supplying the document name is not sufficient. For illustrative purposes, let's say you have collections called test-group1 and test-group2. Now, let's say each of those collection have a document called test: test-group1/test and test-group2/test. If we had written .document('test') as such, there's a conflict because it cannot find said document. That is why you would have to provide the "full path" to the document by also specifying the collection like such: test-group1/test. Also, there's a space between the onWrite and the (). See the Extend Cloud Firestore with Cloud Functions documentation, for more in-depth information.