gpt4 book ai didi

node.js - 在 Firestore 上的文档中设置 DocumentReference (NodeJS)

转载 作者:搜寻专家 更新时间:2023-10-31 22:40:30 28 4
gpt4 key购买 nike

我正在尝试使用 NodeJS v8.6.0 创建一个文档,其中包含对 Firestore 的引用。像这样

const admin = require('firebase-admin')
admin.initializeApp({ credential: MY_CREDENTIAL, databaseURL: MY_DB_URL })
const db = admin.firestore()

const ref = db.doc('foo/someDoc')
db.doc('bar/targetDoc').set({ link: ref })

尽管 ref 是一个 DocumentReference,但结果是

Error: Argument "data" is not a valid Document. Input object is deeper than 20 levels or contains a cycle.

有没有在 NodeJS (Admin)SDK 上做的?


另外,代码中使用的包是

"firebase-admin": "^5.4.1"

console.log(ref)

输出

DocumentReference {
_firestore:
Firestore {
makeAuthenticatedRequest:
{ [Function: makeAuthenticatedRequest]
getCredentials: [Function: bound getCredentials],
authClient: [Object] },
authClient:
Auth {
authClientPromise: null,
authClient: null,
config: [Object],
environment: {} },
baseUrl: undefined,
getCredentials: [Function: bound getCredentials],
globalInterceptors: [],
interceptors: [],
packageJson:
{ name: '@google-cloud/firestore',
version: '0.8.1',
author: 'Google Inc.',
description: 'Firestore Client Library for Node.js',
contributors: [Array],
main: './src/index.js',
files: [Array],
repository: 'googleapis/nodejs-firestore',
keywords: [Array],
dependencies: [Object],
devDependencies: [Object],
scripts: [Object],
license: 'Apache-2.0',
engines: [Object],
types: './types/firestore.d.ts' },
projectId: 'MY_PROJECT',
projectIdRequired: true,
Promise: [Function: Promise],
grpcMetadata: Metadata { _internal_repr: [Object] },
maxRetries: undefined,
userAgent: 'gcloud-node-firestore/0.8.1',
activeServiceMap_: Map {},
protos: {},
_preferTransactions: false,
_lastSuccessfulRequest: null,
api: { Firestore: [Object] },
_referencePath:
ResourcePath {
segments: [],
_formattedName: undefined,
_projectId: 'dewpod-dev',
_databaseId: '(default)' },
app:
FirebaseApp {
firebaseInternals_: [Object],
services_: [Object],
isDeleted_: false,
name_: '[DEFAULT]',
options_: [Object],
database: [Function: bound ],
auth: [Function: bound ],
messaging: [Function: bound ],
storage: [Function: bound ],
firestore: [Function: bound ],
INTERNAL: [Object] },
INTERNAL: FirestoreInternals {} },
_referencePath:
ResourcePath {
segments: [ 'orgs', 'fooOrg' ],
_formattedName: undefined,
_projectId: 'dewpod-dev',
_databaseId: '(default)' } }

完整的错误信息是

/SOME_PATH/node_modules/@google-cloud/firestore/src/validate.js:86
throw new Error(message);
^

Error: Argument "data" is not a valid Document. Input object is deeper than 20 levels or contains a cycle.
at Object.exports.(anonymous function) [as isDocument] (/SOME_PATH/node_modules/@google-cloud/firestore/src/validate.js:86:15)
at WriteBatch.set (/SOME_PATH/node_modules/@google-cloud/firestore/src/write-batch.js:251:14)
at DocumentReference.set (/SOME_PATH/node_modules/@google-cloud/firestore/src/reference.js:416:8)
at Object.<anonymous> (/SOME_PATH/fstest.js:17:20)
at Module._compile (module.js:624:30)
at Object.Module._extensions..js (module.js:635:10)
at Module.load (module.js:545:32)
at tryModuleLoad (module.js:508:12)
at Function.Module._load (module.js:500:3)
at Function.Module.runMain (module.js:665:10)

最佳答案

这是管理 SDK 和 Firestore 的常规 Node SDK 之间交互中的错误。

@google-cloud/firestore 0.8.2 的更新应该可以解决这个问题。

您可以使用 npm update 更新您的项目以获取此更改。

关于node.js - 在 Firestore 上的文档中设置 DocumentReference (NodeJS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46565208/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com