Mongo and there will always be 100 with geodata

While trying to experiment with mongo characteristic, I found strange behavior in my mongo db.

First of all, I filled it in with the following query:

for (i=0; i < 10000000; i++){db.location.insert( {_id: Math.floor((Math.random()*10000000000)+1), position: [Math.round(Math.random()*10000)/10000, Math.round(Math.random()*10000)/10000]} )}

      

following:

db.location.ensureIndex( {position: "2d"} )

      

Then I execute the request:

db.location.find( {position: { $near: [1,1], $maxDistance: 1/111.12  } } )

      

No matter what I try to do, I always get the result or counting 100.

In the documentation, I noticed that the defualt limit is 100. I also tried to override it with more than 100 values. Unfortunately I have failed.

Have you ever encountered such a case?

+1


source to share


3 answers


To get the whole document request like



cordinate = [1,1];
maxDistance = 1/111.12 ;

db.location.find({"position" : {"$within" : 
                                      {"$center" : [cordinate , maxDistance ]}
                                }
                  });

      

+1


source


From the official documentation :

The $ near operator requires a geospatial index: 2dsphere index for GeoJSON points; 2d index for obsolete coordinate pairs. By default, queries using the 2d index return a limit of 100 documents; however, you can use limit () to change the number of results .



Also, see the "Note" on this tutorial page.

Update:
As Sumeet wrote in a comment on his answer, this is an open issue.
To be sure that your query will return the correct count that you specified in the limit method, you can try .limit(<some_number>).explain().n

using your cursor if you are in a shell.

+1


source


Just tried the same scenario on my MongoDB and it works great. I gave a limit of 145 and he gave me 145 entries. However, as mentioned in the documentation, it gives me 100 entries if I don't specify any limits.

db.location.find( {position: { $near: [1,1], $maxDistance: 1  } } ).limit(145)

      

I have tried using the above operator. Please note that I changed the value of $ maxDistance to get a lot of records.

0


source







All Articles