在Firestore(NodeJS)文档中设置DocumentReference [英] Setting a DocumentReference in Document on Firestore (NodeJS)
问题描述
我正在尝试使用NodeJS v8.6.0在Firestore上创建一个带有引用的文档。像这样
const admin = require('firebase-admin')
admin.initializeApp({credential:MY_CREDENTIAL, databaseURL:MY_DB_URL})
const db = admin.firestore()
$ b $ const ref = db.doc('foo / someDoc')
db.doc('bar / targetDoc ').set({link:ref})
虽然 ref
是一个
DocumentReference
,结果是
$ b
错误:参数数据不是有效的文件。输入对象是比$ 20更深的
或者包含一个循环。
有没有办法在NodeJS(Admin) SDK?
另外,代码中使用的包是
firebase-admin:^ 5.4.1
和
console.log(ref)
输出
DocumentReference {
_firestore:
Firestore {
makeAuthenticatedRequest:
{[Function:makeAuthenticatedRequest]
getCredentials:[Function:bound getCredentials],
authClient:[Object]},
authClient:
认证{
authClientPromise:null,
authClient:null,
config:[Object],
environment:{}},
aseUrl:undefined,
getCredentials:[Function:bound getCredentials],
globalInterceptors:[],
拦截器:[],
packageJson:
{名称:'@ google-cloud / firestore',
版本:'0.8.1',
作者:'Google Inc.',
描述:'用于Node.js的Firestore客户端库',
贡献者:[Array],
main:'./src/index.js',
文件:[Array ],
repository:'googleapis / nodejs-firestore',
关键字:[Array],
依赖项:[Object],
devDependencies:[Object],
脚本:[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:{},
_preferTr答案: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 :绑定],
auth:[功能:绑定],
消息:[功能:绑定],
存储:[功能:绑定],
firestore:[功能:绑定],
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
抛出错误(消息);
^
错误:参数data不是有效的Document。输入对象比20级更深或包含一个循环。 (匿名函数)[asDocument](/SOME_PATH/node_modules/@google-cloud/firestore/src/validate.js:86:15)
在WriteBatch.set(/ SOME_PATH/node_modules/@google-cloud/firestore/src/write-batch.js:251:14)DocumentReference.set处的
(/SOME_PATH/node_modules/@google-cloud/firestore/src/reference.js: 416:8)
在Object。< anonymous> (/SOME_PATH/fstest.js:17:20)
在Module._compile(module.js:624:30)
在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)
在Function.Module.runMain(module.js:665:10)
这是admin SDK和Firestore常规节点SDK之间交互中的一个错误。
更新了@ google- cloud / firestore 0.8.2应该解决这个问题。
你可以用 npm update
来更新你的项目来获得这个改变。
I am trying to create a doc with a reference on Firestore with NodeJS v8.6.0. Like this
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 })
Although ref
is a DocumentReference
, it results
Error: Argument "data" is not a valid Document. Input object is deeper than 20 levels or contains a cycle.
Is there anyway to do it on NodeJS (Admin)SDK?
In addition, the package used in the code is
"firebase-admin": "^5.4.1"
and
console.log(ref)
outputs
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)' } }
and the full error message is
/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)
This was a bug in an interaction between the admin SDK and the regular node SDK for Firestore.
An update to @google-cloud/firestore 0.8.2 should fix this issue.
You can update your project with npm update
to get this change.
这篇关于在Firestore(NodeJS)文档中设置DocumentReference的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!