I'm trying to build a shopping list with Firestore. A user belongs to a group. A group has a shopping list. A shopping list has items. A path to a shopping list may look like this /groups/A11C1F3A/ShoppingListA11C1F3A/
where A11C1F3A
is the groupId.
I'm getting an error
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'FIRESTORE INTERNAL ASSERTION FAILED: Invalid document reference. Document references must have an even number of segments, but groups has 1'
and as far as I understand this error it means that there must be something wrong with my data model. I found this question where the accepted answer is saying
A valid path to a collection will always have an odd number of segments; a valid path to a document, an even number.
This is my method:
func saveItemToDB(with itemName: String) {
let db = Firestore.firestore()
if let _ = Auth.auth().currentUser {
let groupId = HomeViewController.groupId
let groupRef = db.collection("groups").document(groupId).collection("ShoppingList" + groupId)
let data: [String: Any] = [
"name" : itemName
]
groupRef.document(itemName).setData(data)
}
}
The number of segments to my collection is three right? I don't see the problem here..