繁体   English   中英

Firebase Firestore-在云功能中使用collectionGroup查询

[英]Firebase firestore - use collectionGroup queries in cloud function

我想在云函数中使用collectionGroup查询,并且仅当我从firebase / app导入时,它才可用:

import * as firebase from 'firebase/app';
const db = firebase.firestore();

...
const snap = await db.collectionGroup('comments').where('foo', '==', 'bar').get();

但是当我尝试部署时,我得到了

TypeError:firebase.firestore不是函数

在我的其他云函数中,我始终从firebase-admin导入,但是打字稿告诉我它没有collectionGroup方法。

import * as admin from 'firebase-admin';
const db = admin.firestore();

目前,我的版本位于最新的以下版本:

"firebase": "^6.2.4",
"firebase-admin": "^8.2.0",

理解为什么要从“ firebase-admin”或“ firebase / app”获取db实例也很高兴。 我不明白为什么会有2个单独的实例。

这应该工作:

import * as admin from 'firebase-admin'
const db = admin.firestore()

const snap = db.collectionGroup('comments').where('foo', '==', 'bar').get()

一个版本支持collectionGroup类型

我建议删除node_modules并重新安装(我只是理智地检查了您的示例,它运行良好,在"firebase-admin": "8.0.0"上没有问题)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM