title: How to perform geospatial queries in mongoose
body: <p>I have using mongoose with NodeJS and have the following model:</p>
  
  <pre><code>var Post = new Schema({
    ...
    location: [Number, Number],
    ...
  });
  Post.index({ location: '2d' });
  Post.set('autoIndex', false);
  module.exports = mongoose.model('Post', Post);
  </code></pre>
  
  <p>When a user makes a query for all posts, they can add an optional query param <em>near</em> to find posts with locations within a given radius of <em>near</em></p>
  
  <pre><code>GET /api/1.0/posts?near=12.3244,-1.23244
  </code></pre>
  
  <p>To get this to work, I'm doing the following:</p>
  
  <pre><code>if(req.query.near) {
    var loc = req.query.near.split(',');
    var area = { center: loc, radius: 10, unique: true, spherical: true };
  
    if(loc.length === 2) {
      query
        .where('location')
        .within()
        .circle(area);
    }
  }
  </code></pre>
  
  <p>And then I execute the query.
  I did this using <a href="http://mongoosejs.com/docs/api.html#query_Query-circle" rel="nofollow">this</a> mongoose documentation</p>
  
  <p>I've got 3 questions:</p>
  
  <ol>
  <li>What is the unit of radius, miles or kilometers?</li>
  <li>Do I divide the radius by 3963.2 like it is done <a href="http://docs.mongodb.org/manual/reference/operator/query/centerSphere/" rel="nofollow">here</a> (the equatorial radius of the earth), or does mongoose handle that? </li>
  <li>What does unique mean? (up above) and spherical? I'm supposing spherical means to use mongo's $centerSphere as opposed to $center, is that right?</li>
  </ol>
  
  <p>I'd appreciate any help, especially for questions 2 and 1
  Thanks :)</p>