Advertisements

RT DB loop to create multiple users

//Runing loop from 0 to 4
        for (int i = 0; i < 5; i++) {
            //Creating a node with the name of user0, user1, user2, user3 and user4 at each iteration
            DatabaseReference myRef = database.getReference("User" + i);
            
            //Creating a user object and appending i to all of its attributes.
            User user = new User("userName" + i, "abc" + i, "xyz" + i, "day" + i, "month" + i, "year" + i);
            
            //Writing each user to Firebase Realtime Database
            myRef.setValue(user);

        }