title: Firebase DB Architecting: filter based on two criteria, favorites and location
body: <p>In my iOS app I'm using Firebase Realtime Database and I have the following models: Users and Venues. </p>
  
  <p>So Users can favorite a Venue. What I want to do is be able to see all the Venues around me that people I follow have favorited. My main issue is I could generate a ‘favoritedFeed’ similar to how <a href="https://github.com/firebase/friendlypix" rel="nofollow noreferrer">FriendlyPix</a> does it, but I really need to consider the distance I am away from the venues and exclude ones that are too far. </p>
  
  <p>Would it be beneficial to just build a ‘favoritedFeed’ of all the venues people I follow favorite, and then filter that feed by distance on the client side? Also I would like to paginate the feed if possible, but if I take this approach, that might not be possible. </p>
  
  <p>I’ll draw my JSON tree, maybe that should be restructured. </p>
  
  <pre><code>users
     [user_id] 
        …
        comments
           [comment_id]  = true
        favorites
           [venue_id] = true
  comments
     [comment_id]
        user = [user_id]
        comment = “…..”
  venues
    [venue_id]
        ...
        favorites
           [user_id] = true
  </code></pre>
  
  <p>Right now I just iterate over all of the Users a user follows and then fetch their comments. That way doesn’t scale very well, but its the only way I can figure out how to get the comments at the moment. </p>