I wanna resolve this question that froze my development.
When i was deploying some Cloud Functions with node 12 to my Firebase project the firebase-cli outputted this:
HTTP Error: 400, Billing account for project 'PROJECT_ID' is not found. Billing must be enabled for activation of service(s) 'cloudbuild.googleapis.com,containerregistry.googleapis.com' to proceed.
So i asked to google like any developer would do and found this question Stack Overflow question.
I changed the package.json in functions directory to:
"engines": {
"node": "8"
}
It worked! But know i'm testing cloud firestore triggers to listen documents with wild card. Here is the code:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
// Getting instance of firestore
const db = admin.firestore();
//Test function
exports.writeToFirestore = functions.firestore
.document('users/{userId}')
.onWrite((change, context) => {
const uid = context.params.userId;
const newDoc = change.after.data();
// Reference to userCards inside lawyer doc
const userCardsDoc = db.doc(`lawyers/lawyer/userCards/userCards`);
const newCard = {
uid: uid,
displayName: newDoc.displayName,
whatsApp: newDoc.whatsApp,
picturePath: newDoc.picturePath
};
userCardsDoc.set({
cardsArray: [newCard]
});
});
When i change the data of any user doc it triggers the function, but the logs show up this: logs image
Someone knows if that type of function trigger doesn't work at all with node 8 and i should enable billing account in this project to deploy with node 10 or latest or the problem is in my code.
I tried to use this function without wild card but still doesn't work!