firebase_tools not found when trying to remove firestore collection from cloud functions

前端 未结 1 1027
刺人心
刺人心 2021-01-14 08:46

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.

<
相关标签:
1条回答
  • 2021-01-14 09:08

    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:

    • Firstly, check you have the 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.
    • Secondly, import it in your Cloud Function with const firebase_tools = require('firebase-tools'); as shown in the sample.

    You will then be able to call firebase_tools.firestore.delete().

    0 讨论(0)
提交回复
热议问题