Firebase Cloud Firestore : Invalid collection reference. Collection references must have an odd number of segments

We Are Going To Discuss About Firebase Cloud Firestore : Invalid collection reference. Collection references must have an odd number of segments. So lets Start this Java Article.

Firebase Cloud Firestore : Invalid collection reference. Collection references must have an odd number of segments

  1. Firebase Cloud Firestore : Invalid collection reference. Collection references must have an odd number of segments

    Then you need change this:
    db.collection("app/users/" + uid + "/notifications")...
    for this:
    db.collection("app").document("users").collection(uid).document("notifications")
    You welcome 😉

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

    Then you need change this:
    db.collection("app/users/" + uid + "/notifications")...
    for this:
    db.collection("app").document("users").collection(uid).document("notifications")
    You welcome 😉

Solution 1

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.

Original Author Bob Snyder Of This Content

Solution 2

Then you need change this:

db.collection("app/users/" + uid + "/notifications")...

for this:

db.collection("app").document("users").collection(uid).document("notifications")

You welcome 😉

Original Author Diego Venâncio Of This Content

Solution 3

You are missing collection reference.
i.e db.collection(** This is getting null **).

Original Author Vikash Sharma Of This Content

Solution 4

I’ve encountered this issue when I provided a wrong entity_Id.

Instead of dojo/default/datasets/fe67ec58-6208-4234-a4ee-98c5dce4665f,
I’ve provided fe67ec58-6208-4234-a4ee-98c5dce4665fand now is working fine.

Original Author Radu Linu Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

Siddharth

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment