Cloud Firestore 节点 SDK - transaction.getAll 不是函数

Cloud Firestore Node SDK - transaction.getAll is not a function

t运行saction .getAll 方法不像 documented 那样工作。我已经复制并粘贴了给定示例中的代码,但它因错误而失败。

Transaction.getAll

从 Firestore 中检索多个文档。对所有返回的文档持有悲观锁。

错误

(node:24009) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: transaction.getAll is not a function

我的代码

这直接从文档中复制并添加了初始化 header。

const firebase = require('firebase-admin');

var serviceAccount = process.env.MY_CREDENTIALS;

firebase.initializeApp({
    credential: firebase.credential.cert(JSON.parse(serviceAccount))
});

const firestore = firebase.firestore();

let firstDoc = firestore.doc('col/doc1');
let secondDoc = firestore.doc('col/doc2');
let resultDoc = firestore.doc('col/doc2');

firestore.runTransaction(transaction => {
  return transaction.getAll(firstDoc, secondDoc).then(docs => {
    transaction.set(resultDoc, {
      sum: docs[1].get('count') + docs[2].get('count')
    });
  });
});

Firebase Admin 发布以来的更新Node.js SDK 5.9.1

这支持 Firestore Node.js 客户端的 v12,其中包括 transaction.getAll

的提交

测试

我从 package.json 中删除了 node_modules 目录和所有依赖项,然后 运行 以下...

包安装

$ npm install --save firebase-admin@5.9.1

> grpc@1.7.3 install /home/jason/Downloads/projects/testing/node_modules/grpc
> node-pre-gyp install --fallback-to-build --library=static_library

[grpc] Success: "/home/jason/Downloads/projects/testing/node_modules/grpc/src/node/extension_binary/node-v57-linux-x64-glibc/grpc_node.node" is installed via remote

> protobufjs@6.8.6 postinstall /home/jason/Downloads/projects/testing/node_modules/google-gax/node_modules/protobufjs
> node scripts/postinstall


> protobufjs@6.8.6 postinstall /home/jason/Downloads/projects/testing/node_modules/google-proto-files/node_modules/protobufjs
> node scripts/postinstall

npm WARN testing@1.0.0 No description
npm WARN testing@1.0.0 No repository field.

+ firebase-admin@5.9.1
added 358 packages in 42.265s

测试代码

(xenial)jason@localhost:~/Downloads/projects/testing$ node testTransactionGetAll.js 
(node:22273) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot read property 'get' of undefined
(node:22273) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

固定

transaction.getAll 已添加到 Google Cloud Firestore Node.js Client This update has been added to the Firebase Admin Node.js SDK v5.9.1

的 v0.12.x

但是,文档中的示例代码不正确。以下行应更改为:

sum: docs[0].get('count') + docs[1].get('count')

之前,它引用了 doc[2],它不存在