angularfire icon indicating copy to clipboard operation
angularfire copied to clipboard

Firebase.update failed: First argument contains an invalid key ($key) in path /$key. Keys must be non-empty strings and can't contain ".", "#", "$",

Open cottom opened this issue 10 years ago • 13 comments

code code today at 5 45 01 pm snappyapp snappyapp today at 5 46 09 pm

  upDateMeetUp(meetup: Meetup): Observable < any > | Promise < any > | any {
    console.log(meetup.$key);
    return this.meetups.update(meetup.$key, meetup);
  }

I don't know what cause this as key and path are right.

cottom avatar Aug 20 '16 09:08 cottom

I konw why..... I didn't remove the $key..

cottom avatar Aug 20 '16 11:08 cottom

@jerry-i , Please can u explain by removing the $key. Thanks

Austyns avatar Jan 29 '17 15:01 Austyns

delete (meetup.$key)

fopnet avatar Jun 03 '17 01:06 fopnet

Do you mean you did not delete $key in meetup? WHy is this needed? I have same problem now. @jerry-i

sharikovvladislav avatar Jun 25 '17 17:06 sharikovvladislav

me too :(

BernardMarieOnzo avatar Jun 29 '17 09:06 BernardMarieOnzo

@jerry-i @BernardMarieOnzo I see only one reason: there is $key property in the firebase db in each item of the list. So, what should firebase do when somebody is trying to update $key prop? This can be the reason.

sharikovvladislav avatar Jun 29 '17 11:06 sharikovvladislav

only because the second param will overwrite all prop but just not this $key, $key is just firebase index.

cottom avatar Jun 29 '17 11:06 cottom

Oh I just re-read the error message:

Keys must be non-empty strings and can't contain ".", "#", "$"

I just realized that this is about keys of object which I pass as 2-nd argument =) I accidently thought that it is about key which I pass as 1st argument.

sharikovvladislav avatar Jun 29 '17 11:06 sharikovvladislav

const $key = obj.$key
delete obj.$key
update($key, object)

cottom avatar Jun 29 '17 12:06 cottom

Ye ye. I understand how to delete prop :) :+1:

I just surprised that I understood error message wrong.

sharikovvladislav avatar Jun 29 '17 12:06 sharikovvladislav

const $key = obj.$key delete obj.$key update($key, object)

I do not understand, please help.

johnjiea avatar Oct 02 '17 08:10 johnjiea

@johnjiea What do you not understand?

You have err in your code:

const $key = obj.$key
delete obj.$key
update($key, object); // <--- update($key, obj);

sharikovvladislav avatar Oct 02 '17 09:10 sharikovvladislav

@jerry-i thanks it worked for me.

kpnigalye avatar Dec 11 '17 16:12 kpnigalye