title: How to limit the child retrieved in Firebase Android
body: <p>I want to ask about how to retrieve data with limited child in Android Firebase. Here is my data structure :</p>
  
  <pre><code>"chatrooms":
      "chatroom_id_1" :
          "message":
              "message_id_1":1
              "message_id_2":1
              "message_id_3":1
              "message_id_4":1
              "message_id_5":1
              "message_id_6":1
              "message_id_7":1
              "message_id_8":1
              "message_id_9":1
              "message_id_10":1
              "message_id_11":1
      "chatroom_id_2" :
              "message":
                  "message_id_12":1
                  "message_id_13":1
                  "message_id_14":1
                  "message_id_15":1
                  "message_id_16":1
                  "message_id_17":1
                  "message_id_18":1
                  "message_id_19":1
                  "message_id_20":1
                  "message_id_21":1
                  "message_id_22":1
  </code></pre>
  
  <p>From the structure above how to do the query to retrieve a snapshot with only data limited to 5 messages?</p>
  
  <p>The dataSnapshot I would like to have is like this : </p>
  
  <pre><code>DataSnapshot { 
      key = chatroom_id_1, 
      value = {
          messages={
              message_id_1=1,
              message_id_2=1,
              message_id_3=1,
              message_id_4=1,
              message_id_5=1
          }
      }
  }
  DataSnapshot { 
          key = chatroom_id_2, 
          value = {
              messages={
                  message_id_12=1,
                  message_id_13=1,
                  message_id_14=1,
                  message_id_15=1,
                  message_id_16=1
              }
          }
      }
  </code></pre>
  
  <p>is it possible to do so? Because most of the tutorial I've found can only limit the child retrieved but not the inner child. Thanks</p>
  
  <p>EDIT : MY message_id is generated randomly, so to obtain the message_id I have to use an DataSnapshot with iterator . Here's my retrieve data code</p>
  
  <pre><code>public void retrieveChatRoom(final Callback callback){
          DatabaseReference ref = reference.child("chatrooms");
          ref.addValueEventListener(new ValueEventListener() {
              @Override
              public void onDataChange(DataSnapshot dataSnapshot) {
                  callback.onDataChanged();
                  Iterator i = dataSnapshot.getChildren().iterator();
                  while (i.hasNext()) {
                      DataSnapshot dataSnapshot1 = (DataSnapshot) i.next();
                      callback.dataReceived(dataSnapshot1);
                  }
              }
  
              @Override
              public void onCancelled(DatabaseError databaseError) {
  
              }
          });
      }
  </code></pre>
  
  <p>the thing is the DataSnapshot return all of the chat_message inside my chatroom,can I limit it to only returning 5 messages?</p>