I've looked everywhere, and simply can't figure this out... I can get it to work in the mongo shell, but not in my application. Here's the code. I can get it to work here... (using the MongoDB shell)
db.runCommand({geoNear: 'prints', near: {type:"Point",coordinates:[30.3,-40]}, spherical:true})
but it does not work in my app (using the native mongodb driver)
db.prints.geoNear({type: 'Point',coordinates:[30.3,-40]}, {spherical:true}, function(err, docs){
if(err){res.json(400, err);}
else{res.json(200, docs);}
});
I have no idea what the issue is? I'm pretty sure my index is correct (as it works when I use the Mongo Shell direclty) but I can't get it to work with the native node driver... I keep getting a really cryptic error back...
{
name: "MongoError"
errmsg: "exception: 'near' field must be point"
code: 17304
ok: 0
}
and when I look that error up, it's listed, but I get a 404 page for some reason??? Any help would be greatly appreciated, I've been banging my head against this wall for a day...
UPDATE: I got this via a work-around... by forcing a command through the native-driver directly to Mongo... but I'm still perplexed as to why the native-driver doesn't support geoJSON - instead the geoNear command is forcing a legacy coordinate system...
mongo.db.command({
geoNear: 'prints', near: {"type":"Point","coordinates":[30.3,-40]}, spherical: true, num: 10000, maxDistance: req.body.radius
}, function(err, docs){
if(err){res.json(400, err);}
else{res.json(200, docs);}
});
Feature request to the native-driver team?