MongoDB Geospatial Query Count Issue (Always 100)

对着背影说爱祢 提交于 2019-12-04 17:45:49

Try "within" instead of "near". This works for me,

center = [50, 50];
radius = 1/111.12; //convert it to KM.

db.places.count({"loc" : {"$within" : {"$center" : [center, radius]}}})

I found this at https://jira.mongodb.org/browse/SERVER-856

For what it's worth, even though the count reported for the cursor is 100 (regardless of what limit you give the query, even "10") you actually get the "limit" number of results back when you run through the query.

Here's a link to an issue where they assert it isn't broken:

Hope that helps!

miss.serena

It is not an issue with the mongo query. Try using cursor.size() rather than cursor.count(). Count does not take into account the limit where size does. So if you use .size() instead of count() you should get a print out of the correct number of returned items.

Check out this stack overflow Q and A for a clear solution to your issue. Difference between cursor.count() and cursor.size() in MongoDB

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!