MongoDB地理空间查询计数问题

MongoDB地理空间查询计数问题

本文介绍了MongoDB地理空间查询计数问题(始终为100)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于包含100多个结果的地理空间查询,计数操作似乎存在问题.如果运行以下查询,无论如何我仍然会得到100的计数.

It appears there is an issue with the count operation on a geospatial query that contains more than 100 results. If I run the following query I still get a count of 100 no matter what.

db.locations.find({"loc":{$nearSphere:[50, 50]}}).limit(1000).count()

我了解使用"near"语法的查询的默认大小限制为100,但看来您返回的值不能超过该限制.我是在做错什么,还是有解决方法?

I understand that the default size limit on a query that uses the "near" syntax is 100 but it appears you cannot return more than that. Am I doing something wrong or is there a workaround for this?

推荐答案

尝试在内部"而不是附近".这对我有用,

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]}}})

我在 https://jira.mongodb.org/browse/SERVER-856

这篇关于MongoDB地理空间查询计数问题(始终为100)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 16:43