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

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

问题描述

我正在使用以下代码在集合中查询文档.文档名称与设备名称相同.设备名称是从API传递到文档的,当设备名称包含字母"/"(如Motorola C380/C385)时,我得到了一个错误.我收到错误

I am querying a collection for documents using below code. Document names are same as device names. The device name is passed to the document from an API I am getting an error when a device name contains letter "/" like Motorola C380/C385. I get an error

java.lang.IllegalArgumentException:无效的文档引用.文档引用必须具有偶数个段,但是手机/摩托罗拉C380/C385具有3

java.lang.IllegalArgumentException: Invalid document reference. Document references must have an even number of segments, but Mobiles/Motorola C380/C385 has 3

我知道我收到此错误,因为FireStore将斜线后的名称C385视为文档内的集合.我想知道在文档名称可以包含"/"的情况下如何摆脱这种情况,在将其插入到集合中之前应该检查并删除它,还是有更好的解决方案?

I know I am getting this error because FireStore considers the name C385 after slash as a collection inside a document. I want to know how to get rid of situations like this when a document name can contain a "/" should I check and remove this before inserting it into my collection or is there any better solution?

firebaseFirestore.collection("Mobiles").document(response.body().get(finalI).getDeviceName())

推荐答案

尝试一下

response.body().get(finalI).getDeviceName().toString().replace("/","_")

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

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