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

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

问题描述

这个查询有什么问题?

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 文档中有一个 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天全站免登陆