title: Geographic queries in NoSQL
body: <p>Our team is currently working on some killer ios location app that we fear "explode" in a good way, so we want to put effort thinking about scalability and Availability.</p>
  
  <p>After we read that draw something is based on couchbase NoSQL, we scanned the couch base api (specifically the .net one) and found solutions to all of our app requirements except one, and we describe the scenario:</p>
  
  <ol>
  <li>Let's say we have order of 1,000,000 users around the world, with their location specified by longitude and latitude;</li>
  <li>We have a user circle range c:  it's location (specified by longitude and latitude) and a radius rc</li>
  <li>We want to efficiently determine which of the users are in the circle.</li>
  </ol>
  
  <p>If we write it in sql server as we did now it's something like this:</p>
  
  <pre><code>CREATE TABLE UserLocations
  [UserId] [bigint] NOT NULL,
  [CurrentLocation] [geography] NOT NULL
  
  ALTER PROCEDURE sp_GetCurrentUsersInRange
  @userPoint geography, 
  @RangeInMeters int
  AS
  BEGIN
  
  select  UserId from UserLocations
  where @userPoint.STDistance(CurrentLocation) &lt;= @RangeInMeters
  and UserId &lt;&gt; @userId
  
  END
  </code></pre>
  
  <p>But this is NoSQL, there are only keys (such as longitude key and latitude key), but we can’t fetch all the values and query them all in memory
  , can't we?</p>
  
  <p>So the question to you is:
  Is there a way you know how to accomplish such thing in NoSQL?</p>
  
  <p>Thank you</p>
  
  <p>p.s. our related question in Stackoverflow: <a href="https://stackoverflow.com/questions/10211579/how-to-determine-n-locations-inside-a-circle-efficiently">How to determine n locations inside a circle efficiently?</a></p>
  
  <p>EDIT:
  Couchbase support had answered me!
  their answer as quoted:</p>
  
  <p><em>"Our geo-spatial indexing is a feature being debuted in 2.0 (scheduled out later this year) as experimental and will move to fully supported in a later release. We are also in the process of building the necessary client-side interfaces for it, but there is nothing available at the moment.
  Lastly, the distance and bounding circle (among others) are features that we will develop as we move forward."</em></p>