Firebase Cloud Firestore:无效的收藏参考。集合引用必须具有奇数个段 [英] Firebase Cloud Firestore : Invalid collection reference. Collection references must have an odd number of segments

查看:751
本文介绍了Firebase Cloud Firestore:无效的收藏参考。集合引用必须具有奇数个段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下面的代码,并得到一个错误:

I have the following code and getting an error :

Invalid collection reference. Collection references must have an odd number of segments

以及代码:

private void setAdapter() {
        FirebaseFirestore db = FirebaseFirestore.getInstance();
        db.collection("app/users/" + uid + "/notifications").get().addOnCompleteListener(task -> {
            if (task.isSuccessful()) {
                for (DocumentSnapshot document : task.getResult()) {
                    Log.d("FragmentNotifications", document.getId() + " => " + document.getData());
                }
            } else {
                Log.w("FragmentNotifications", "Error getting notifications.", task.getException());
            }
        });
    }


推荐答案

分层数据结构和子集合是如文档中所述。集合包含文档,文档可能包含子集合。这个结构总是一个收集和文件的交替模式。文档中包含了对这个例子的描述:

Hierarchical data structures and subcollections are described in the documentation. A collection contains documents and a document may contain a subcollection. The structure is always an alternating pattern of collections and documents. The documentation contains this description of an example:


注意收集和文档的交替模式。您的
收藏和文件必须始终遵循这种模式。您不能
引用集合中的集合或文档中的文档。

Notice the alternating pattern of collections and documents. Your collections and documents must always follow this pattern. You cannot reference a collection in a collection or a document in a document.

因此,集合的有效路径将总是有奇数段;一个文档的有效路径,一个偶数。由于你的代码试图查询一个集合,所以四个路径的长度是无效的。

Thus, a valid path to a collection will always have an odd number of segments; a valid path to a document, an even number. Since your code is trying to query a collection, the path length of four is invalid.

这篇关于Firebase Cloud Firestore:无效的收藏参考。集合引用必须具有奇数个段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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