Angularfire: AngularFire2 - Setting custom key when pushing

Created on 10 Nov 2016  路  7Comments  路  Source: angular/angularfire

Angular:
2.0.1

Firebase:
2.4.30

AngularFire:
2.0.0-beta-4

Currently I am using:

 this.af.database.list('users').push(user);

How can I make the key of the object that is submitted be custom. So I want to be able to set the node of this object to the same uid of the registered user. I have access to this Id I just need to be able to know how to make the custom user objects node not be the auto generated id when pushing.

Thanks

Most helpful comment

@StevenAderson Lists will always auto-generate, which is good thing! If you need to specify your own key in a list, then a use object(key: string).

this.af.database.object(`list/myCustomKey`).update({ age: 101 });

All 7 comments

@StevenAderson Lists will always auto-generate, which is good thing! If you need to specify your own key in a list, then a use object(key: string).

this.af.database.object(`list/myCustomKey`).update({ age: 101 });

Thanks it works great!

Yes, but what if I need a generated key in order to use it later in other collection, but for this particular collection, I need to replace the key and keep the content? How can I update only the key?

@coltaemanuela You cannot update keys. You can create a new key with the same content and delete the other one however.

Is this possible with firestore?

@davideast ,

This solution this.af.database.object(list/myCustomKey).set(values) is not working for me. If I want to insert a new value, first time it works, but second time with same myCustomKey if I try its updating the previous value, instead rejecting.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Leanvitale picture Leanvitale  路  3Comments

cre8 picture cre8  路  3Comments

itisparas picture itisparas  路  3Comments

jnupeter picture jnupeter  路  3Comments

Maistho picture Maistho  路  3Comments