By user5640752

2018-03-13 15:53:29 8 Comments

I am experimenting with manipulating data in firebase and have run into the following question:

If i have 2 records inside of a subdirectory (A), and want to move them to subdirectory (B) how do i do this in javascript?

   - A
      - KEY 1 data
      - KEY 2 data
   - B

I am thinking copy the contents to a new record that saves to directory B and delete the directory A record, but does firebase provide an easier way to just move the record?


@user5640752 2018-03-14 13:59:31

So I came across this solution it will copy the code in your old directory and recreate it to the new directory..

moveFbRecord: function(oldRef, newRef){    
         oldRef.once('value', function(snap)  {
            newRef.set( snap.val(), function(error) {
                   if( !error ) {   }
                   else if( typeof(console) !== 'undefined' && console.error ) {  console.error(error); }

@Alex Mounir 2018-03-13 16:08:21

Referring to

You can update multiple nodes in a single operation. So after reading the initial data you want to manage you can set their fields to null to delete them and set the new ones to the target values

@Doug Stevenson 2018-03-13 15:56:10

Firebase Realtime Database doesn't provide a move operation. You have to read the existing data, write it to the new location, then remove the data at the original location.

Related Questions

Sponsored Content

25 Answered Questions

[SOLVED] Change an element's class with JavaScript

  • 2008-10-12 20:06:43
  • Nathan Smith
  • 2164317 View
  • 2334 Score
  • 25 Answer
  • Tags:   javascript html dom

18 Answered Questions

[SOLVED] Checking if a key exists in a JavaScript object?

38 Answered Questions

[SOLVED] Is there an "exists" function for jQuery?

  • 2008-08-27 19:49:41
  • Jake McGraw
  • 675513 View
  • 2380 Score
  • 38 Answer
  • Tags:   javascript jquery

28 Answered Questions

1 Answered Questions

Limit number of records in firebase

8 Answered Questions

[SOLVED] Check if element exists in jQuery

  • 2011-01-04 10:15:11
  • Nick
  • 1093773 View
  • 1045 Score
  • 8 Answer
  • Tags:   javascript jquery

1 Answered Questions

2 Answered Questions

[SOLVED] Move firebase records

2 Answered Questions

[SOLVED] Difference between Grunt, NPM and Bower ( package.json vs bower.json )

2 Answered Questions

[SOLVED] What is the best way to change a key in firebase?

Sponsored Content