gong15A
gong15A

Reputation: 87

CollectionReference.doc() requires its first argument to be of type non-empty string

I have an ionic app trying to update the records in firebase. I keep on getting this error. Not sure what I am doing wrong.

Error: Uncaught (in promise): FirebaseError: [code=invalid-argument]: Function CollectionReference.doc() requires its first argument to be of type non-empty string, but it was: a custom Object object

FirebaseError: Function CollectionReference.doc() requires its first argument to be of type non-empty string, but it was: a custom Object object

this is my update function.

updateTodo(todo: Todo, id: string) {

    return this.todosCollection.doc(id).update(todo)
}

Upvotes: 4

Views: 21051

Answers (5)

Juan Carlos Jiron
Juan Carlos Jiron

Reputation: 488

In my case I was passing a number type variable in the .doc function but it requires a string. Verify that your "id" variable has a value and it is not undefined, null or and empty string.

Upvotes: 1

Mahmoud Farargy
Mahmoud Farargy

Reputation: 97

I had this problem and solved it by typing .doc(cred.user.uid) instead of .doc(cred.user.id).

Upvotes: 0

Blessing
Blessing

Reputation: 2720

Go where you're calling that function updateTodo use uid instead of id.

Upvotes: 0

Keith
Keith

Reputation: 77

The problem is on the id that you are passing in doc,it is supposed to be a string..try logging its value just to check what you are exactly passing

Upvotes: 0

Nándor Szűcs
Nándor Szűcs

Reputation: 151

This happens when you are trying to send an empty object to firebase. I had this error when I reset my form values before the async call could finish..

Upvotes: 1

Related Questions