Add an item to a list in Firebase Database
<p>I have the following Firebase database structure. <code>uIds</code> is a type of <code>List&lt;String&gt;</code>. I am trying to add another uId under <code>uIds</code> with an incremented index. <code>setValue()</code> and <code>updateChildren()</code> would require me to retrieve existing data, and <code>push()</code> will add an item with a randomly generated string as a key instead of an incremented index. Is there a simpler way that does not require to retrieve the existing data? Thanks!</p>

<pre><code>  "requests" : {
    "request001" : {
      "interests" : [ "x" ],
      "live" : true,
      "uIds" : [ "user1" ]  // &lt;---- from this
    },
    "request002" : {
      "interests" : [ "y" ],
      "live" : true,
      "uIds" : [ "user2" ]
    }
  }
</code></pre>

<h2>--------------------------------</h2>

<p>Edit:</p>

<p>Sorry for the unclarity. Let me elaborate to make it clear.
Say I have the above database and want to update it to the following.</p>

<pre><code>  "requests" : {
    "-KSVYZwUQPfyosiyRVdr" : {
      "interests" : [ "x" ],
      "live" : true,
      "uIds" : [ "user1", "user2" ]   // &lt;--- to this
    },
    "-KSl1L60g0tW5voyv0VU" : {
      "interests" : [ "y" ],
      "live" : true,
      "uIds" : [ "user2" ]
    }
  }
</code></pre>

<p>ishmaelMakitla's suggestion, <code>mDatabase.child("requests").child("request001").setValue(newRequest)</code>, will overwrite the "request001" with "newRequest". So I should retrieve the existing data of "request001" and add "user2" to the list <code>uIds</code>. It will be something like this:</p>

<pre><code>mDatabase.child("requests").child("request001").addListenerForSingleValueEvent(new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
        Request newRequest = dataSnapshot.getValue(Request.class);
        newRequest.uIds.add("user2");
        mDatabase.child("requests").child("request001").setValue(newRequest);
    }

    @Override
    public void onCancelled(DatabaseError databaseError) {}

});
</code></pre>

<p>But I am wondering if this process is necessary since what I am trying to do is simply to add one item to the list <code>uIds</code>.</p>