Firebase无效的文档参考.文档引用必须具有偶数个段 [英] Firebase Invalid document reference. Document references must have an even number of segments

查看:63
本文介绍了Firebase无效的文档参考.文档引用必须具有偶数个段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此查询出了什么问题?

What is wrong with this query?

const db = firebase.firestore()
const query = db.doc(this.props.user.uid).collection('statements').orderBy('uploadedOn', 'desc').limit(50)

我收到以下错误:

Uncaught Error: Invalid document reference. Document references must have an even number of segments, but FrMd6Wqch8XJm32HihF14tl6Wui2 has 1
    at new FirestoreError (index.cjs.js:346)
    at Function.DocumentReference.forPath (index.cjs.js:15563)
    at Firestore.doc (index.cjs.js:15368)
    at UploadStatementPresentation.componentWillMount (UploadStatementPage.jsx:61)
    at UploadStatementPresentation.componentWillMount (createPrototypeProxy.js:44)
    at callComponentWillMount (react-dom.development.js:6872)
    at mountClassInstance (react-dom.development.js:6968)
    at updateClassComponent (react-dom.development.js:8337)
    at beginWork (react-dom.development.js:8982)
    at performUnitOfWork (react-dom.development.js:11814)

推荐答案

由于您没有描述您要查询的内容,因此,我仅指出所有文档必须无一例外地位于集合中.所以,如果你这样说:

Since you haven't described what exactly you're trying to query, I'll just point out that all documents must be in a collection, without exception. So, if you say this:

db.doc(this.props.user.uid)

Firestore假定您要传递给doc()的字符串包含用斜杠分隔的集合和文档ID.但这在您的情况下似乎极不可能.您需要确定uid所在的集合,并在构建对要查询的集合的引用时首先使用该uid.假设您在uid文件中确实有一个statements子集合,并且其他集合中包含uid文件,则必须指定完整路径,如下所示:

Firestore assumes that the string you're passing to doc() contains both the collection and document id separated by a slash. But this seems to be highly unlikely in your case. You need to determine which collection the uid is in, and use that first when you build the reference to the collection you want to query. Assuming that you do have a statements subcollection in the uid document, and that some other collection contains the uid document, you'll have to specify the full path like this:

db.collection('that-other-collection').doc(this.props.user.uid).collection('statements')

当然,只有您知道数据的实际结构.

Of course, only you know the actual structure of your data.

这篇关于Firebase无效的文档参考.文档引用必须具有偶数个段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆