In Cloud Functions for Firebase, I am trying to run admin.firestore.batch(), but I am receiving error "admin.firestore.batch is not a function", see (totally simplified) example.
exports.getTest = functions.https.onRequest((request, response) => {
cors(request, response, () => {
var batch = admin.firestore.batch(); // <--- ERROR HERE
var docRef = admin.firestore().doc('tariffs/1')
batch.set(docRef, 'name', 'free');
return batch.commit();
}).then(() => {
response.status(200).send({result: 'success'});
});
});
My package.json is
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"dependencies": {
"cors": "^2.8.1",
"firebase-admin": "^5.4.2",
"firebase-functions": "^0.7.1"
},
"private": true
}
Is it possible to use firebase.firestore.batch() with Cloud Functions?
Thank you
You are missing the ()
after admin.firestore
.
Change this:
var batch = admin.firestore.batch(); // <--- ERROR HERE
to this:
var batch = admin.firestore().batch();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With