I am trying write an aggragation function to update a few details on a value change of a nested object of a doc in wildcard.
exports.createAccessDetails = functions.firestore.document('classrooms/{classId}/access/{accessType}').onWrite((snap, context) => {
// const data = snap.data();
const { classId, accessType } = context.params;
console.log(snap);
console.log(classId, accessType);
return null;
});
Then updating the object like on a button click
function setAccess() {
const date = Date.now();
Firebase.firestore.collection('classrooms')
.doc('1570776211111').update({
[`access.writeAccess.${date}`]: true
});
}
What am I doing wrong? Why the function didnt trigger?
collection('classrooms').doc('1570776211111')
but your Cloud Function is defined to be triggered when you write tocollection('classrooms').doc('1570776211111').collection('access').doc('xyz')
. So were do you exactly want to update? in collectionclassrooms
or in theaccess
sub-collection of a classroom? – Renaud Tarnecclassrooms
has a huge object where I'm updating a keyaccess
which has another key calledwriteAccess
or another type, with different data. Currently, I didn't createaccess
as a different collection, I'm pushing it as an object of the collectionclassrooms
. Now from Pepe's comment I understand if I have to listen for a change in the object ofaccess/{accessType}
I have to makeaccess
a subclass ofclassrooms
, is that correct? If so, I have to rewrite my query too? Currently querying based onfirestore.collection('classrooms').where(
access.readAccess.${id}, '==', true)
? – Subhendu Kundu