I have a user object in firebase that I need to move to another child node on the same tree.
The structure is like so:
users -> male -> uid -> ......KVPs..objects...etc
-> female -> uid -> ......KVPs..objects...etc
I need to keep users separated by gender due to the nature of the app. If a user changes their gender I want to move all their details to that selected gender.
I tried using AngularFire (firebaseObject) but it throws errors when I tried to set it in firebase due to the keys present in the object. I tried striping out the keys, using JSON.stringify, angular.toJSON but am not having any luck!!
I'm wondering is there a cleaner or recommended way to do this? Appreciate If anyone has any pointers or can assist in anyway.
Many Thanks, Noel
This is actually pretty easy
// firebase ref
desc.ref1 = new Firebase(desc.userRef+'/'+desc.oldGender+'/'+uid);
desc.ref2 = new Firebase(desc.userRef+'/'+desc.gender+'/'+uid);
desc.ref1.on("value", function(snapshot) {
console.log(snapshot.val());
desc.ref2.set(snapshot.val());
}, function (errorObject) {
console.log("The read failed: " + errorObject.code);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With