Firebase Invalid document reference. Document references must have an even number of segments

前端 未结 3 1188
生来不讨喜
生来不讨喜 2021-01-18 05:57

What is wrong with this query?

const db = firebase.firestore()
const query = db.doc(this.props.user.uid).collection(\'statements\').orderBy(\'uploadedOn\',          


        
3条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-18 06:55

    Since you haven't described what exactly you're trying to query, I'll just point out that all documents must be in a collection, without exception. So, if you say this:

    db.doc(this.props.user.uid)
    

    Firestore assumes that the string you're passing to doc() contains both the collection and document id separated by a slash. But this seems to be highly unlikely in your case. You need to determine which collection the uid is in, and use that first when you build the reference to the collection you want to query. Assuming that you do have a statements subcollection in the uid document, and that some other collection contains the uid document, you'll have to specify the full path like this:

    db.collection('that-other-collection').doc(this.props.user.uid).collection('statements')
    

    Of course, only you know the actual structure of your data.

提交回复
热议问题