文档引用在集合引用上必须具有偶数个段错误 [英] Document references must have an even number of segments error on a collection reference

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

问题描述

我遇到了一个非常简单的错误:

I'm getting the rather simple error:

Document references must have an even number of segments.

我知道它在告诉我什么以及如何解决它,但是在收集参考中却给了我这个错误.

I'm aware of what it is telling me and how to fix it, however it is giving me this error on a collection reference.

CollectionReference collectionReference = getFirebaseInstance()
.collection(Constants.USERS)
.document(userId)
.collection(Constants.CONTACTS);

在我的数据库中,路径为(COLLECTION)<文件>(收集)<文档>我正在尝试在用户/{id}/联系人中获取该用户的所有联系人,但这只是抛出此错误,有什么想法吗?

In my database the path is (COLLECTION) < DOCUMENTS > (COLLECTION) < DOCUMENTS > I'm trying to get all contacts for a user at users/{id}/contacts but it just throws this error, any ideas?

getFirebaseInstance是我创建的一种始终获取当前值的方法

getFirebaseInstance is a method I've created to always get the current

FirebaseFirestore.getInstance();

推荐答案

您的userId变量中可能带有斜线.文档ID不能带有斜线,因为在形成文档的路径"时,它们被理解为集合和文档之间的分隔符.

Your userId variable probably has a slash in it. Document ids can't have slashes, since they are interepreted as dividers between collections and documents when forming the "path" to a document.

字符串也可能为空,这是无效的.

It's also possible that the string may be empty, which is invalid.

这篇关于文档引用在集合引用上必须具有偶数个段错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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