5

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

1 Answer 1

20

You are missing the () after admin.firestore.

Change this:

var batch = admin.firestore.batch(); // <--- ERROR HERE 

to this:

var batch = admin.firestore().batch(); 
Sign up to request clarification or add additional context in comments.

1 Comment

Oh god, such a silly mistake... Thank you, Bob Snyder

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.