1

I have a Realtime Database of A Daily Routine App which has a General Node and An Edited Node, In the general node, each weekday is listed, inside which all the objectives in that particular day is listed.

The general functionality is, Suppose Today is Tuesday, Oct 11, 2022 I want the data from the general>Tuesday node to be copied into Edited>11102022. If the 11102022 node doesn't exists then I am making that node and then copying the data.

I am currently doing this client sided only, meaning the client needs to have write access to the database which in the final product, I don't want to include.

I currently am thinking of cloud functions after reading some docs about what it can do. But I have next to no knowledge about this and the docs and other videos don't demonstrate my solution, they only talk about how to review incoming data and other things.

Is there any Easy to follow guide or Which docs should I read to find a solution? Any help with this will be a great help.

Client side copying I am following @Alex Mamo's answer from Moving or copying data from one node to another in firebase database

This is my Database snapshot

Ayush Sha
  • 23
  • 7
  • So to understand better, do you need the code for a cloud function that copies the data within a node from one location to another, in the way it does the client code? – Alex Mamo Oct 12 '22 at 08:02
  • Yes, the user will send a request and the function will copy it, if it already isn't copied before by any other user. – Ayush Sha Oct 12 '22 at 16:39
  • Hi @AlexMamo, I tried searching for these and didn't find anything helpful. Any updates from your side? – Ayush Sha Oct 14 '22 at 13:04

1 Answers1

0

Sorry for being late, I not so sure for official code but I did like this :

    FirebaseDatabase db = FirebaseDatabase.getInstance();
    DatabaseReference ref= db.getRefernce();

    ref.child("tempuser").child(userID).addListenerForSingleValueEvent(new ValueEventListener() {
                    @Override
                    public void onDataChange(@NonNull DataSnapshot snapshot) {
                        if(snapshot.exists()) {
                            reference.child("user").child(userID).setValue(snapshot.getValue());
                        }
                    }

                    @Override
                    public void onCancelled(@NonNull DatabaseError error) {

                    }
                });

Here I am moving a "tempuser" , single user node under "userID" data to permenant "user" node with same "userID" as singe user node.

Hope it helps .

su00n
  • 31
  • 5