简体   繁体   中英

How to avoid empty documents in a Firestore query?

I'm trying to display some data which is hosted under a subcollection coll1 that exist in doc1 using this code:

val query = db!!.collection("coll1").document(doc1)
    .collection("coll2").orderBy("field1", Query.Direction.ASCENDING)

The problem is when I use this code, the doc1 variable isn't generated yet so I get this error:

Invalid document reference. Document references must have an even number of segments

How can I avoid this error till I generate doc1 ?

您需要知道所有集合和文档的确切名称才能执行查询,因此只有在拥有doc1的字符串值(该值标识了组织子集合的文档)之后才可以执行查询。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM