4

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)
}
Community
  • 1
  • 1
gong15A
  • 77
  • 1
  • 2
  • 3
  • What exactly is the value of `id`? Use a debugger or log the value to show exactly what you're passing. – Doug Stevenson Aug 15 '19 at 02:29
  • Are you sure that your `id` is not null or empty? – Alex Mamo Aug 15 '19 at 07:08
  • I had a similar issue which I solved by correcting the doc reference, which in your case is the "id". Just make sure that the value of "id" in your code is a valid reference string for a firebase document. – rhythmo Apr 06 '20 at 23:42

5 Answers5

1

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..

Nándor Szűcs
  • 151
  • 1
  • 9
1

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.

0

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

Keith
  • 37
  • 1
0

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

Blessing
  • 2,450
  • 15
  • 22
  • Welcome to Stack overflow! This seem to be a comment but not an answer. Please see [How do I write a good answer?](https://stackoverflow.com/help/how-to-answer) – coderpc Sep 23 '20 at 16:46
0

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