I'm trying to setup a Cloud Function that, when ran by Cloud Scheduler, will insert certain data into my Firestore Database. I am doing this in Node.js using the Inline editor provided when creating my Cloud Function.
I keep getting the error:
"Error: function crashed. Details: 7 PERMISSION_DENIED: Missing or insufficient permissions."
On my Firebase dashboard, the logs show my function and the error that I get when I test my Cloud Function, so I'm assuming my function is hitting the database, just not adding the dummy data I was testing with.
index.js:
const Firestore = require('@google-cloud/firestore');
const PROJECTID = 'MY_PROJECT_ID';
const firestore = new Firestore({
projectId: PROJECTID,
timestampsInSnapshots: true,
});
/**
* Responds to any HTTP request.
*
* @param {!express:Request} req HTTP request context.
* @param {!express:Response} res HTTP response context.
*/
exports.helloWorld = (req, res) => {
return firestore.collection("users").add({
first: "Ada",
last: "Lovelace",
born: 1815
});
};
Package.json:
{
"name": "sample-http",
"version": "0.0.1",
"dependencies": {
"@google-cloud/firestore": "0.17.0",
"semver": "^5.5.1"
}
}
I also have my rules set for my database as:
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write;
}
}
}