I have next database list (usernames + user id).
How can i find object by user id and change his key (username)?
I'm using AngularFire2 with Angular 5.
I have next database list (usernames + user id).
How can i find object by user id and change his key (username)?
I'm using AngularFire2 with Angular 5.
You can find a child node by its value with a query like this:
var users = firebase.database().reference("usernames");
var query = users.orderByValue().equalTo("Sk6I..."ltA2");
By attaching a listener to this query you'll be able to find the reference and the key of the user (or "any users", since technically there may be more keys with the same value) matching the UID.
But you can't rename a node. You'll have to remove the existing node, and create a new one. For more on this see:
Solution for my case:
this.db.list('usernames', ref => ref.equalTo(uid)).remove() // Remove old value
this.db.list('usernames', ref => ref.equalTo(uid)).set(
username, uid
) // Create new value