I am trying to remove a collection using callable firebase function.
I took a sample code from here.
The sample code has a "firebase_tools" element.
return firebase_tools.firestore
.delete(path, {
project: process.env.GCLOUD_PROJECT,
recursive: true,
yes: true,
token: functions.config().fb.token
})
Which apparently is not part of firebase-function
I am getting following error in function logs:
Unhandled error ReferenceError: firebase_tools is not defined
The document also mentions that:
You can import any function of the Firebase CLI into your own Node.js application using the firebase-tools package.
But I couldn't figure out how to do it.
Edit: Learning nodejs basics will help you a lot when working with firebase functions.
If you look in the same document you refer to, you will find a link to the sample code: https://github.com/firebase/snippets-node/tree/master/firestore/solution-deletes
Then if you look at the Cloud Function code (index.js
) you will see that this sample starts as follows:
const admin = require('firebase-admin');
const firebase_tools = require('firebase-tools');
const functions = require('firebase-functions');
admin.initializeApp();
So you need to:
firebase-tools
package correctly installed. Normally this should be the case since you are most probably already using the Firebase CLI (see https://github.com/firebase/firebase-tools). In case not, install it with npm i firebase-tools
.const firebase_tools = require('firebase-tools');
as shown in the sample.You will then be able to call firebase_tools.firestore.delete()
.
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