我有以下代码并收到错误:
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());
}
});
}
原文由 Relm 发布,翻译遵循 CC BY-SA 4.0 许可协议
文档 中描述了分层数据结构和子集合。集合包含文档,文档可能包含子集合。该结构始终是集合和文档的交替模式。该文档包含示例的描述:
因此,一个集合的有效路径总是有奇数个段;文档的有效路径,偶数。由于您的代码正在尝试查询集合,因此路径长度为 4 是无效的。