我有以下代码并收到错误:
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());
}
});
}
那么你需要更换它:
db.collection("app/users/" + uid + "/notifications")...
with it:
db.collection("app").document("users").collection(uid).document("notifications")
不客气 ;)
--2023 年更新--
如果您使用新的 Firebase Modular,请记住参考:
Firebase 需要更改引用:“集合名称”/“文档名称”/“集合名称”/“文档Id”等
setDoc(doc(db, "collectionName", userID, "anotherCollectionName", documentID), ...
ref
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)