1

I only want to insert 5 data maximum. How can I restrict the input amount

Here is my code to insert the data to firebase database

DatabaseReference myRef = FirebaseDatabase.getInstance()
    .getReference().child("Users")
    .child(FirebaseAuth.getInstance().getCurrentUser().getUid()).child("Wishlist");
                

myRef.push().setValue("http://www.librarything.com/isbn/" + passURL).addOnCompleteListener(new OnCompleteListener<Void>() {
    @Override
    public void onComplete(@NonNull Task<Void> task) {
        if(task.isSuccessful()){//show it if complete
            Toast.makeText(web_view.this, "Added to wishlist", Toast.LENGTH_SHORT).show();
        }else{//just error handler
            Toast.makeText(web_view.this, "Something went wrong", Toast.LENGTH_SHORT).show();
        }
    }
}); 

Here is my data base screenshot

As you can see in picture "Wishlist" had 1 data and I want to set the data limit to 5 maximum in "Wishlist"

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807

0 Answers0