Reputation: 79
what i am trying to do is ... my document flow
batch(collection) -> {batchName}(document) -> subjects -> {subjectName} -> attendance
i want to trigger firestore function whenever there is an update in the attendance object
So in the documentation of the Cloud Firestore triggers, i found this line "Your trigger must always point to a document" with an example ... here is the link to the documentation
which gave me hope that it is possible to do that and i am failing to achieve this,
exports.attendenceTrigger = functions.firestore.document('batche/{batchName}/subjects/{subjectName}/attendance')
is it possible to do it ? if yes then what am i doing wrong?
Upvotes: 0
Views: 81
Reputation: 50830
You have specified a path to a collection
'batche/{batchName}/subjects/{subjectName}/attendance'
(col) (doc) (col) (doc) (col)
However, your path must point towards a document so valid paths include:
// Triggers a function when a doc in subjects sub-collection is changed
'batche/{batchName}/subjects/{subjectName}'
// or
// Triggers a function when a doc in attendance sub-collection is changed
'batche/{batchName}/subjects/{subjectName}/attendance/{attendanceId}'
Is attendance
a sub-collection? If yes, then use the second path above to listen trigger a function when a document in that collection is created/modified/deleted. If attendance
is a field in a {subjectName}
document then you should use the first line and access the attendance
field from the snapshot snapshot.data().attendance
.
Upvotes: 1