gpt4 book ai didi

node.js - Firebase 无效的文档引用。文档引用必须有偶数个段

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

这个查询有什么问题?

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)

最佳答案

由于您没有具体说明您要查询的内容,我只是指出所有文档都必须在一个集合中,无一异常(exception)。所以,如果你这样说:

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

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

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

当然,只有您自己知道数据的实际结构。

关于node.js - Firebase 无效的文档引用。文档引用必须有偶数个段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50653608/

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