javascript - 无法使用 Functions:Shell 将新文档添加到 Firestore 中的集合
问题描述
我正在尝试使用 Firebase shell 将文档添加到 Firestore 中的子集合:
firebase functions:shell
运行它为我们提供了一个外壳,我们可以在其中运行查询和代码。似乎出于某种奇怪的原因,我无法将add
文档记录到集合中。
这是我在 shell 中运行的脚本:
await db.collection('balances')
.doc(docId)
.collection('history')
.add({x: 'a'});
这很简单,但 Firebase 似乎不喜欢将该对象传递给 add 函数。
我能够到达谷歌的 Firestorevalidate.js
文件中一切都失败的确切行。
function extractBaseClassName(value) {
let constructorName = 'Object';
while (Object.getPrototypeOf(value) !== Object.prototype) {
value = Object.getPrototypeOf(value); // <===== This returns null instead of an Object for some reason
constructorName = value.constructor.name;
}
return constructorName;
}
这是确切的错误消息堆栈:
(node:90760) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'constructor' of null
at extractBaseClassName (/Users/Moose/Development/crypto-accumulator/functions/node_modules/@google-cloud/firestore/build/src/validate.js:35:33)
at Object.customObjectMessage (/Users/Moose/Development/crypto-accumulator/functions/node_modules/@google-cloud/firestore/build/src/validate.js:55:26)
at Object.validateDocumentData (/Users/Moose/Development/crypto-accumulator/functions/node_modules/@google-cloud/firestore/build/src/write-batch.js:608:36)
at CollectionReference.add (/Users/Moose/Development/crypto-accumulator/functions/node_modules/@google-cloud/firestore/build/src/reference.js:1765:23)
at runB (repl:43:6)
at process._tickCallback (internal/process/next_tick.js:68:7)
更新:预感...
我相信问题可能在于Object.getPrototypeOf(value) !== Object.prototype
评估true
它应该是什么时候,false
因为它{x: 'a'}
是一个对象
解决方案
看来对象不是问题。我试图在我的 Firestore 中重现它并使用以下命令:
let docId = 'test_document3'
async function f1() {
await db.collection('test_collection').doc(docId).collection('inside-collection').add({ x: 'c'})
}
f1()
文档已添加,没有问题。你可以尝试同样的方法。
推荐阅读
- c# - 如何在 Telerik Report Viewer 中显示/隐藏导出选项?
- sql - 使用带多个条件 SQL 的左连接
- c# - 我在 c# 中使用 html 代码和 css 来设计按钮,但我不知道如何在单击后将其重定向到另一个页面(ASP.net)
- javascript - 在外部 html 页面中所做的更改不起作用
- css - Fontawesome5 图标不适用于 Drupal 8 中的伪代码
- rabbitmq - rabbitmq-server 没有启动(状态=64)
- python - PySpark-亚马逊评论情绪分析-RDD问题
- javascript - 如何在ajax中插入一个数组?
- ios - 我们在哪里可以在 Metal 中使用点坐标系
- java - JIRA客户端不断抛出一个现有的连接被远程主机异常强行关闭