I am trying to increment "numberOfEvents" field in Users collection whenever an event (in Events collection) is created. How do I do this, I know the below code is wrong I just copied it from firebase documentation. Please help.
rules_version = '2';
const functions = require('firebase-functions');
function increment() {
exports.myFunction = functions.firestore
.document('Events/{docId}')
.onCreate((change, context) => {
get(/databases/$(database)/documents/Users/$(request.auth.uid)).data.numberOfEvents + 1; });
}
service cloud.firestore {
// Do not change this
match /databases/{database}/documents {
// Path to your document
match /Users/{docId} {
allow read;
allow write;
}
match /Events/{docId} {
allow read;
allow write: if get(/databases/$(database)/documents/Users/$(request.auth.uid)).data.numberOfEvents < 16;
}
}
}