尝试从云函数中删除Firestore集合时找不到firebase_tools [英] firebase_tools not found when trying to remove firestore collection from cloud functions

查看:101
本文介绍了尝试从云函数中删除Firestore集合时找不到firebase_tools的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用可调用的firebase函数删除集合.

我从此处中获取了示例代码. /p>

该示例代码具有一个"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

文档还提到:

您可以使用firebase-tools包将Firebase CLI的任何功能导入到自己的Node.js应用程序中.

但是我不知道该怎么做.

解决方案

如果查看所引用的同一文档,则会找到示例代码的链接: index.js ),您将看到此示例开始如下:

const admin = require('firebase-admin');
const firebase_tools = require('firebase-tools');
const functions = require('firebase-functions');

admin.initializeApp();

所以您需要:

  • 首先,检查是否已正确安装 firebase-tools 软件包.通常应该是这种情况,因为您很可能已经在使用Firebase CLI(请参见 https://github.com /firebase/firebase-tools ).如果没有,请使用npm i firebase-tools安装.
  • 第二,如示例所示,使用const firebase_tools = require('firebase-tools');将其导入您的Cloud Function中.

您将可以拨打firebase_tools.firestore.delete().

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 a own Node.js application using the firebase-tools package.

But I couldn't figure out how to do it.

解决方案

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().

这篇关于尝试从云函数中删除Firestore集合时找不到firebase_tools的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆