Firebase: Query.on failed: Was called with 1 argument. Expects at least 2
<p>The error is in the title.</p>

<p>The app I´m building is based on React and Firebase.
I am trying to use promises.
Here is my code:</p>

<pre><code>gamesRef.on('value').then(function(snapshot){
      // find all empty games
      var gamesToRemove = [];
      snapshot.forEach(game =&gt; {

        if(game.val().player1 == ""
          &amp;&amp; game.val().player2 == ""
          &amp;&amp; game.val().player3 == ""
          &amp;&amp; game.val().player4 == ""){
            gamesToRemove.push(game.key());
        }
      });
      return gamesToRemove;
    }).then(function(gamesToRemove){
      // remove all empty games
      for(var index in gamesToRemove){
        gamesRef.child(gamesToRemove[index]).remove();
      }
    }, function(error){
      console.log(error);
    });
</code></pre>

<p>I found <a href="https://stackoverflow.com/questions/35526205/firebase-promise-query-once-failed-was-called-with-1-argument-expects-at-lea">this question on SO</a> that addressed the same issue. The solution was that the Firebase version needs to be at least 2.4 to use promises. I used an older version, but after upgrading to 2.4.2, i still get the same error. What should I do?</p>

<p>Edit: Code after fix. Get error "gamesRef.on(...).then is not a function". </p>

<pre><code>gamesRef.on('value', function(snapshot){
      // find all empty games
      var gamesToRemove = [];
      snapshot.forEach(game =&gt; {

        if(game.val().player1 == ""
          &amp;&amp; game.val().player2 == ""
          &amp;&amp; game.val().player3 == ""
          &amp;&amp; game.val().player4 == ""){
            gamesToRemove.push(game.key());
            console.log("denna borde raderas: " + game.key());
        }
      });
      return gamesToRemove;

    }).then(function(gamesToRemove){
      // remove all empty games
      for(var index in gamesToRemove){
        gamesRef.child(gamesToRemove[index]).remove();
      }
    });
</code></pre>