Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Document references must have an even number of segments error on a collection reference

I'm getting the rather simple error:

Document references must have an even number of segments.

I'm aware of what it is telling me and how to fix it, however it is giving me this error on a collection reference.

CollectionReference collectionReference = getFirebaseInstance()
.collection(Constants.USERS)
.document(userId)
.collection(Constants.CONTACTS);

In my database the path is (COLLECTION) < DOCUMENTS > (COLLECTION) < DOCUMENTS > I'm trying to get all contacts for a user at users/{id}/contacts but it just throws this error, any ideas?

getFirebaseInstance is a method I've created to always get the current

FirebaseFirestore.getInstance();
like image 779
martinseal1987 Avatar asked Jul 05 '18 15:07

martinseal1987


1 Answers

Your userId variable probably has a slash in it. Document ids can't have slashes, since they are interepreted as dividers between collections and documents when forming the "path" to a document.

It's also possible that the string may be empty, which is invalid.

like image 60
Doug Stevenson Avatar answered Oct 12 '22 19:10

Doug Stevenson