Jie*_*eng 4 node.js firebase google-cloud-firestore
这个查询有什么问题?
const db = firebase.firestore()
const query = db.doc(this.props.user.uid).collection('statements').orderBy('uploadedOn', 'desc').limit(50)
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
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)
Run Code Online (Sandbox Code Playgroud)
Dou*_*son 17
由于您尚未描述您要查询的内容,我只是指出所有文档都必须位于集合中,无一例外.所以,如果你这样说:
db.doc(this.props.user.uid)
Run Code Online (Sandbox Code Playgroud)
Firestore假定您传递给的字符串doc()包含由斜杠分隔的集合和文档ID.但在你的情况下,这似乎是不太可能的.您需要确定uid所在的集合,并在构建对要查询的集合的引用时首先使用该集合.假设你statements在uid文档中有一个子集合,并且其他一些集合包含uid文档,你必须指定完整的路径,如下所示:
db.collection('that-other-collection').doc(this.props.user.uid).collection('statements')
Run Code Online (Sandbox Code Playgroud)
当然,只有您知道数据的实际结构.
| 归档时间: |
|
| 查看次数: |
8990 次 |
| 最近记录: |