简体   繁体   English

在两个集合上进行MongoDB地理搜索

[英]MongoDB Geo Search on two collections

I'm trying to figure out a way to geo query two collections: 我正在尝试找出一种地理查询两个集合的方法:

  1. Person {name, age, groupid}
  2. 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: 有两种方法:

  • MR (Map Reduce) This would actually entail outputting to a summary table first so I don't recommend this really. MR(Map Reduce)这实际上首先需要输出到汇总表,所以我不建议这样做。
  • Event based Pre-aggregation. 基于事件的预聚合。 When a user joins or leaves a group you get their age and update the aggregated field accodingly. 当用户加入或退出组时,您可以确定其年龄并以编码方式更新汇总字段。

I would personally go for the event based pre-aggregated method of doing things 我会亲自参加基于事件的预先汇总的处理方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM