AngularFire2 how to use your own custom key instead of the auto generated one

Jason picture Jason · Nov 10, 2016 · Viewed 6.9k times · Source

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

Answer

Jesse Te Weehi picture Jesse Te Weehi · Dec 20, 2016

Use a method like below with Angularfire2

addCustomKey (key, value) {
    const toSend = this.af.database.object(`/users/${key}`);
    toSend.set(value);
}