Move/Copy Firebase Object to Another Child Node

Hi All,

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..object...etc
         -> female -> uid -> ......KVPs..object...etc

I need to keep users seperated 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 $$conf present in the object. I tried striping out the keys, using JSON.stringify, anfular.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, think i got tunnel vision…haha

        // 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());

            // write to user object to new location
			desc.ref2.set(snapshot.val());

		}, function (errorObject) {
			console.log("The read failed: " + errorObject.code);
		});

HTH

1 Like