On Mon, 8 Apr 2013, Marian Steinbach wrote:
> *$near* seems to have the problem that it cannot be combined with
> $uniqueDocuments = true and only returns a hard coded limit of 100
> hits. And I also have the impression that $maxDistance doesn't have an
> effect. Or at least it's not using meters as a unit.
Near should always only return unique docs.
> $geoWithin: I am trying this query:
>
> db.locations.find({
> 'nodes.location': {
> $geoWithin:
> {$center: [[7.2, 50.8], 1000]}
> }
> }
> )
>
> It seems as if this works in general, but the unit for the radius parameter
> is unclear. It's definitely not meters. I see the result getting smaller
> when I change it to some very small number like 0.1.
Providing you use MongoDB 2.4 and a "2dsphere" index, it's in meters. In
other cases it can be in radians, which you can convert that to KM by
dividing that by the radius of the Earth (6371) - or to meters, by
dividing by 6371000.
> Also I'd like the result to be sorted by distance, but that's not a
> strong requirement. Additionally, I should note that I'm not talking
> about several hundrets of kilometers as a radius, but instead
> everything up to 1000 meters.
$near should make order by distance by default. You're not quite saying
which MongoDB you use, and what index (types), so it's a bit hard to
give a more precise answer. I'd almost suggest you use something like
the following to do what you want with MongoDB 2.4 and the aggregation
framework:
maxDist = 500;
rEarth = 6371000;
res = db.poiConcat.aggregate( [ {
'$geoNear' : {
'near' : [ -0.122055, 51.514562 ],
'distanceField' : 'distance',
'distanceMultiplier' : rEarth,
'maxDistance' : maxDist / rEarth,
'spherical' : true,
'query' : {
'$or' : [
{ ts: 'amenity=pub' },
{ ts: 'amenity=bar' },
]
}
}
} ] )
Of course, you probably need to change the 'query'.
cheers,
Derick
--
{
website: [ "
http://mongodb.org", "
http://derickrethans.nl" ],
twitter: [ "@derickr", "@mongodb" ]
}