【发布时间】:2019-12-22 01:14:20
【问题描述】:
我目前正在尝试构建一个云功能来将我的 Firestore 数据导出到我的存储桶。
我在 Firebase 文档中找到的关于如何执行此操作的唯一示例:
https://googleapis.dev/nodejs/firestore/latest/v1.FirestoreAdminClient.html#exportDocuments
示例
const firestore = require('@google-cloud/firestore');
const client = new firestore.v1.FirestoreAdminClient({
// optional auth parameters.
});
const formattedName = client.databasePath('[PROJECT]', '[DATABASE]');
client.exportDocuments({name: formattedName})
.then(responses => {
const response = responses[0];
// doThingsWith(response)
})
.catch(err => {
console.error(err);
});
从那个例子来看,我似乎需要安装 @google-cloud/firestore 作为我的云函数的依赖项。
但我想知道是否可以使用仅firebase-admin 包访问这些方法。
我想到了这一点,因为 firebase-admin 已经将 @google-cloud/firestore 作为依赖项。
> firebase-admin > package.json
"dependencies": {
"@firebase/database": "^0.4.7",
"@google-cloud/firestore": "^2.0.0", // <---------------------
"@google-cloud/storage": "^3.0.2",
"@types/node": "^8.0.53",
"dicer": "^0.3.0",
"jsonwebtoken": "8.1.0",
"node-forge": "0.7.4"
},
问题:
是否可以仅使用firebase-admin 获取FirestoreAdminClient 的实例并使用exportDocuments 方法?
或者我真的需要将@google-cloud/firestore 安装为直接依赖项并直接使用它吗?
【问题讨论】:
标签: node.js firebase google-cloud-firestore google-cloud-functions firebase-admin