Start a new topic

Array of _geoloc coordinates and geoNear

I have products that are located in multiple retail locations. For each retailer, I am included their long/lat in the _geoloc of the product as an array. There may 10's or 100's of retailers per product.

If I use regular $near in my query, it seems to work but will give me the same document multiple times if more than one location in _geoloc is within max distance. I only want the single document.

Using geoNear, I don't seem to be getting any filtering at all. I just get 100 records (max returned allowed) every time.

Do you have an example for geoNear in action with say, a 3 mile radius?

Hey Daniel, We don't have a sample for that specific use case right now (we have geoloc samples but they're rather simple in their querying structure). It could be that MongoDB doesn't support that, and you'd have to use BL to de-dupe.

To help me look into this problem, can you share the specific query?
Let me rephrase the issue...there are duplicate documents in the results. The geoNear function pre mongo2.6 uses a 'uniqueDocs' flag to specifit whether to return the same doc more than once but that doesn't appear to be working.

Here's the BL query:

collection.geoNear(long,lat,{maxDistance:1/3959, uniqueDocs:true,includeLocs:true, spherical:true,distanceMultiplier:3959},myCallback);

Hi Caroline, any response from the devs as to whether it is working correctly or not? A simple example would be to do the following:

Create a new collection.

Add a column called _geoloc.

Add a doc with _geoloc array of positions: [[1.01,2.01],[1.011,2.011]]

Run a geoNear BL function and see if you get the same doc more than once:

collection.geoNear(1.015,2.015,{maxDistance:1/3959, uniqueDocs:true,includeLocs:true, spherical:true,distanceMultiplier:3959},myCallback);

We don't support the uniqueDocs flag currently, but will be supporting it in the near future.
Are you thinking days, weeks or months? Just want to plan out whether I need a different data model in the meantime.
Hey @"Daniel Roizman"‌ , we're planning on upgrading to Mongo 2.6 within the week, so that should fix the geoNear problem.
The database is now upgraded!
Login or Signup to post a comment