Firebase function not being triggered
Clash Royale CLAN TAG#URR8PPP
Firebase function not being triggered
Hello I am trying to trigger subcollections in a document here is my code,
exports.updateCounter = functions.firestore
.document('journeys/journeyId/collectionId/id')
.onWrite((change, context) =>
const docRef = change.after.ref;
const collectionId = context.params.collectionId;
const eventType = context.eventType;
const uid = context.auth.uid;
console.log("Update Counter called!");
console.log("Event type: "+ eventType);
console.log("Userid: " + uid);
);
But the function does not seem to get triggered, My database is something like this:
journey/id/comment/commentid/like/likeid
journey/id/comment/commentid/likeshard/shardId
When the shardId is updated or the likeid the function is not triggered
here is my rules
match /journeys/journey {
allow read, write: if request.auth.uid != null;
allow delete: if request.auth.uid == resource.data.author_id;
match /comment/document=**
allow read, update, delete, create: if request.auth.uid != null;
and when deploying the function:
i deploying functions
i functions: ensuring necessary APIs are enabled...
+ functions: all necessary APIs are enabled
i functions: preparing functions directory for uploading...
i functions: packaged functions (41.41 KB) for uploading
+ functions: functions folder uploaded successfully
i functions: uploading functions in project: updateCounter(us-central1)
i functions: updating Node.js 6 function updateCounter(us-central1)...
+ functions[updateCounter(us-central1)]: Successful update operation.
+ Deploy complete!
1 Answer
1
The wildcard path in your Firestore function doesn't exactly match either of the document paths that you're trying to change. The number of path elements has to be exactly the same. Your function is looking at documents that have 4 path elements:
journeys/journeyId/collectionId/id
but your changed documents have 6 path elements:
journey/id/comment/commentid/like/likeid
You'll have to more specifically call out the subcollections that you're interested in.
Also, I'll note that your function says "journeys", but your changed documents say "journey". But fixing that still won't help here.
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.