Mongoose version: 3.6 Node version: 0.10
I tried to solve this problem for hours. I want to find all documents closer than maxDistance to some coordinates. I am trying to use GeoJSON specifications for MongoDB (2dsphere) so that I can enter the distance in meters.
This is my venue.js schema:
var db = require('mongoose'), Schema = db.Schema, ObjectId = Schema.ObjectId; var venueSchema = new Schema({ geo: { type: [Number], index: '2dsphere'}, city: String, name: String, address: String }); module.exports = db.model('Venue', venueSchema);
Here I insert the ctrlVenue.js request:
var Venue = require('../models/venue.js'); VenueController = function(){}; exports.getVenues =function(req, res) { var maxDistance = typeof req.params.maxDistance !== 'undefined' ? req.params.maxDistance : 0.09;
When I run the code, I get an error message:
"Error # 101: CastError: failed on number with error for value \" [object Object] \ "at path \" geo \ ""
If I change this line:
$near: lonLat,
with
$near: geo,
I receive documents correctly, but then I can not use counters as a unit of measure. I based my assumptions on the following table: http://docs.mongodb.org/manual/reference/operator/query-geospatial/
I saw many examples of work using $ geometry, but not one along with $ next. What am I doing wrong?
source share