【问题标题】:error passing empty credentials to firestore emulator将空凭据传递给 Firestore 模拟器时出错
【发布时间】:2020-02-23 00:12:29
【问题描述】:

我正在尝试将一些示例数据播种到我的本地 Firestore 模拟器数据库中。我改编了this github issue的示例

我的代码如下所示:

const {Firestore} = require('@google-cloud/firestore');
const {credentials} = require('grpc');

const db = new Firestore({
  projectId: 'my-project-id',
  servicePath: 'localhost',
  port: 8100,
  sslCreds: credentials.createInsecure(),
  customHeaders: {
    "Authorization": "Bearer owner"
  }
});

async function load_data() {
  await db.collection("mycollection").doc("myid").set({ foo: "test" })
}
load_data();

但我收到错误提示

this.credentials._getCallCredentials 不是函数

在节点 10 和 12 上测试,错误相同。

库版本:

  • @google-cloud/firestore 3.5.1
  • grpc 1.24.2

是否有更好的方法来写入本地模拟 Firestore?还是我的代码有问题?

【问题讨论】:

    标签: node.js firebase google-cloud-firestore grpc


    【解决方案1】:

    这里的问题是您试图同时使用两种不同的 gRPC 实现。 Firestore 内部使用@grpc/grpc-js,所以这就是您应该使用的。您只需要将第二行更改为 const {credentials} = require('@grpc/grpc-js'); 并将依赖项切换到该库即可。

    【讨论】:

      猜你喜欢
      • 2018-10-28
      • 1970-01-01
      • 1970-01-01
      • 2022-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多