firebase_tools 尝试从云函数中删除 firestore 集合时未找到
firebase_tools not found when trying to remove firestore collection from cloud functions
我正在尝试使用可调用的 firebase 函数删除集合。
我从 here 中获取了示例代码。
示例代码有一个“firebase_tools”元素。
return firebase_tools.firestore
.delete(path, {
project: process.env.GCLOUD_PROJECT,
recursive: true,
yes: true,
token: functions.config().fb.token
})
这显然不是 firebase-function
的一部分
我在函数日志中收到以下错误:
Unhandled error ReferenceError: firebase_tools is not defined
文档还提到:
You can import any function of the Firebase CLI into your own Node.js application using the firebase-tools package.
但我不知道该怎么做。
编辑:学习 nodejs 基础知识将对您使用 firebase 函数有很大帮助。
如果您查看所引用的同一文档,您会发现 link 示例代码:https://github.com/firebase/snippets-node/tree/master/firestore/solution-deletes
然后,如果您查看 Cloud Function 代码 (index.js
),您将看到此示例的开头如下:
const admin = require('firebase-admin');
const firebase_tools = require('firebase-tools');
const functions = require('firebase-functions');
admin.initializeApp();
所以你需要:
- 首先,检查你有
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)。如果没有,请使用 npm i firebase-tools
. 安装它
- 其次,如示例所示,使用
const firebase_tools = require('firebase-tools');
将其导入您的 Cloud Function。
然后您就可以致电 firebase_tools.firestore.delete()
。
我正在尝试使用可调用的 firebase 函数删除集合。
我从 here 中获取了示例代码。
示例代码有一个“firebase_tools”元素。
return firebase_tools.firestore
.delete(path, {
project: process.env.GCLOUD_PROJECT,
recursive: true,
yes: true,
token: functions.config().fb.token
})
这显然不是 firebase-function
的一部分
我在函数日志中收到以下错误:
Unhandled error ReferenceError: firebase_tools is not defined
文档还提到:
You can import any function of the Firebase CLI into your own Node.js application using the firebase-tools package.
但我不知道该怎么做。
编辑:学习 nodejs 基础知识将对您使用 firebase 函数有很大帮助。
如果您查看所引用的同一文档,您会发现 link 示例代码:https://github.com/firebase/snippets-node/tree/master/firestore/solution-deletes
然后,如果您查看 Cloud Function 代码 (index.js
),您将看到此示例的开头如下:
const admin = require('firebase-admin');
const firebase_tools = require('firebase-tools');
const functions = require('firebase-functions');
admin.initializeApp();
所以你需要:
- 首先,检查你有
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)。如果没有,请使用npm i firebase-tools
. 安装它
- 其次,如示例所示,使用
const firebase_tools = require('firebase-tools');
将其导入您的 Cloud Function。
然后您就可以致电 firebase_tools.firestore.delete()
。