[英]MongoDB Geo Search on two collections
I'm trying to figure out a way to geo query two collections: 我正在尝试找出一种地理查询两个集合的方法:
Person {name, age, groupid}
Groups (id, name, geoLocation[x,y])
I need to find all near groups with persons with age > 18
我需要找到所有
age > 18
人群
Any idea how to do it without having to query the groups for each found person? 任何想法如何做到而不必查询每个找到的人的组?
You have no joins in MongoDB so you need to find another way around this. 您在MongoDB中没有联接,因此您需要找到另一种解决方法。
The next plausable method I would think of would be to store an array of age ranges with the group record: 我想到的下一个可能的方法是使用组记录存储年龄范围的数组:
{
_id: {},
name: {},
geoLocation: {},
age_groups: {
'gt18': 1
},
}
And then I would just query on that age_groups.gt18 field and pull out all records. 然后,我只查询该age_groups.gt18字段并提取所有记录。 This does mean, of course, you will require something to keep this field upto date.
当然,这的确意味着您需要一些内容来使此字段保持最新。 There are a couple of methods:
有两种方法:
I would personally go for the event based pre-aggregated method of doing things 我会亲自参加基于事件的预先汇总的处理方法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.