Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

firestore Error: Argument "documentPath" must point to a document

I build react native app with firebase/firestore and I get the error

Error: Argument "documentPath" must point to a document.

when I write this line

    var userStatusFirestoreRef = firebase.firestore().doc('/status/' + uid);

all code

    firebase.auth().signInAnonymouslyAndRetrieveData().then((user) => {
    var uid = firebase.auth().currentUser.uid;

    var userStatusFirestoreRef = firebase.firestore().doc('/status/' + uid);
});
like image 766
Manspof Avatar asked Apr 16 '18 16:04

Manspof


3 Answers

You should chain the collection() and doc() methods for each segment of the firestore path, example:

firebase.firestore().collection('status').doc(uid)

You can chain these as far as your subcollections and subdocuments go.

firebase.firestore().collection('status').doc(uid).collection('messages').doc('messageId')

like image 153
Nicholas Pesa Avatar answered Oct 07 '22 02:10

Nicholas Pesa


UPDATE : now you can't put a forward slash '/' in a document's name, it throws the error:

firebase.firestore().collection().doc(*) 'document path' must point a docment

like image 26
YosefBro Avatar answered Oct 07 '22 00:10

YosefBro


I found the error, it should be

    var userStatusFirestoreRef = firebase.firestore().doc('status/' + uid);

with one '/' at the end of 'status/'

like image 2
Manspof Avatar answered Oct 07 '22 00:10

Manspof