'Firebase Realtime Database overwrites old data while adding new

Hi there i'm facing issue that FB realtime DB deletes old data while inserting a new one here is my code

 String text = reviewText.getText().toString();
                if (text.length() > 15){
                    int rating = (int) ratingBar.getRating();
                    String uuid = firebaseAuth.getCurrentUser().getUid();
                    Map<String, String> data = new HashMap();
                    data.put("rating", String.valueOf(Integer.parseInt(String.valueOf(rating))));
                    data.put("comment", text);
                    DatabaseReference  db = firebaseDatabase.getReferenceFromUrl("dburl").child("attr_reviews").child(placename);
                    db.setValue(uuid).addOnCompleteListener(new OnCompleteListener<Void>() {
                        @Override
                        public void onComplete(@NonNull Task<Void> task) {
                            if(task.isSuccessful()){
                                db.child(uuid).setValue(data).addOnCompleteListener(new OnCompleteListener<Void>() {
                                    @Override
                                    public void onComplete(@NonNull Task<Void> task) {
                                        if (task.isSuccessful()){

                                        }else {
                                            Toast.makeText(getActivity(), R.string.eReviewErrUnkw, Toast.LENGTH_LONG).show();
                                        }
                                    }
                                });
                            }else {
                                Toast.makeText(getActivity(), R.string.eReviewErrUnkw, Toast.LENGTH_LONG).show();
                            }
                        }
                    });

                }else {
                    Toast.makeText(getActivity(), R.string.eReviewErrTxt, Toast.LENGTH_LONG).show();

                }

I have tried to put push() into diffrent positions but still same. DB structure looks like this It should create DB structure like this on image

enter image description here

Edit: Database structure should look like this

enter code here
DB
 └attr_reviews
             └city1
                  └useruuid1
                           └comment: ""
                           └rating: x
                  └useruuid2
                           └....
            └city2
                 └....


Solution 1:[1]

The data in the database is getting overwritten, what you need to do is use push() which would create a random id for you in the database:

db.child(uuid).push().setValue(data).addOnCompleteListener(new OnCompleteListener<Void>() {

This way you will have the following database:

uuid
  random-id1
       comment: "comment"
       rating: 1
  random-id2
       comment: "comment"
       rating: 1

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Peter Haddad