Firebase query: exclude data where a specific field is null
<p>I have a query that fetches data between 2 dates, using startAt (1 week ago) and endAt (now) on the last_visit fields.</p>

<p>Then I loop through the results to discard users who don’t have a profile picture.</p>

<p>Problem is around 20% of the users have a profile picture, so just to get 100 users with profile pictures, I have to query at least 500 people (I use limitToLast(500)).</p>

<p>Could I make this query more efficient, by somehow specifying something like in SQL: WHERE profile_picture IS NOT NULL?</p>

<p>If possible, I could also use only limitToLast(100) if it was possible to only take the users that do have a profile picture set.</p>

<p>Database looks like:</p>

<pre><code>users: {
  {user_uid}: {
     profile_picture: null,
     last_visit: 123456789
  }
  {user_uid}: {
     profile_picture: 'example.com/pic.png',
     last_visit: 123456789
  }
}
</code></pre>