-1

I want to change this data from Table DraftUsers to Table PublishedUser. But I have no idea of how I can perform this. Please Help....

{
  "DraftUsers": {
     "CtHFL9hwgfe1oUUVMyqz8BSDDSJ2": "CtHFL9hwgfe1oUUVMyqz8BSDDSJ2",
      "CtHFL9hwgfe1oUUVMyqz8BSFG045": "CtHFL9hwgfe1oUUVMyqz8BSFG045"
      "EKGFUHFL9hwgfe1oUUVMyqz8BSHF78465": "EKGFUHFL9hwgfe1oUUVMyqz8BSHF78465",
      "FGSGHG3275hwgfe1oUUVMyqz8BSFG045": "FGSGHG3275hwgfe1oUUVMyqz8BSFG045"
   }
}
  • Realtime Database does not provide a way to rename a node. The best you can do is copy the data to a new node and delete the original. – Doug Stevenson Aug 21 '21 at 05:24

1 Answers1

0
    final DatabaseReference db = FirebaseDatabase.instance.reference();
    db.child('DraftUsers').once().then((result) async { 
      var yourData = result.value;
      var response = await db.child('PublishedUser').set(yourData);
    });

Note: if you want to change specific values, you iterate result.value or get them by ids/keys

Naveen Avidi
  • 3,004
  • 1
  • 11
  • 23