mongodb geoNear +额外的过滤器?
在mongodb中使用geoNear时是否可以添加更多过滤器?例如,假设我的记录如下所示:
{
_id: {},
cid: 1,
latlon: [ -74.07096147537231, 40.9088747684256 ]
}
我可以传递“cid”以确保只有“cid”等于“1”的记录吗?如果 geoNear 无法实现,我该怎么做?我正在使用 geoNear 因为它返回距离...
谢谢!
Is it possible to add more filters when using geoNear in mongodb? For example, say I my records look like the following:
{
_id: {},
cid: 1,
latlon: [ -74.07096147537231, 40.9088747684256 ]
}
Can I pass "cid" to be sure that only the records with a "cid" that equals "1"? If it is not possible with geoNear, how would I do this? I am using geoNear because it returns the distance...
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,当然有可能。您可以像往常一样使用 $near 进行任何过滤:
更新:
如果需要距离,请使用
db.runCommand
,如果不需要距离 --db.collection.find像往常一样。
来自文档:
db.runCommand
中有一个query
参数,你可以这样使用它:Yes, sure it's possible. You can use any filtering with $near as usual:
Update:
If you need distance use
db.runCommand
, if no need distance --db.collection.find
as usual.From documentation:
There is
query
parameter indb.runCommand
, you can use it like this: