如何构建来自多个集合的关系数据

时间:2014-12-01 05:53:55

标签: mongodb meteor

我是编写应用程序的新手,我创建了一个应用程序,我需要为每个用户提供国家城市状态数据,以便他们可以让人们知道他们住在哪里。

我一直在搜索包含该数据的数据集以及如何使用它。

我能找到的所有数据都是关系结构的,所以城市有州和国家的ID

我知道可以编写查询来将这些数据收集到一些格式中,以便他们选择他们所居住的国家/州和城市(虽然我需要了解如何)但我想知道是否有是一种更好的存储数据的方法,这样我就不必跳过箍来获取数据。我希望使用Meteor的Easy Search软件包来实现这一目标。

我正在处理的当前数据集来自Geobytes GeoWorldMap http://www.geobytes.com/GeoWorldMap.zip

数据集示例如下所示

Countries
"CountryId","Country","FIPS104","ISO2","ISO3","ISON","Internet","Capital","MapReference","NationalitySingular","NationalityPlural","Currency","CurrencyCode","Population","Title","Comment"
1,"Afghanistan","AF","AF","AFG","4","AF","Kabul ","Asia ","Afghan","Afghans","Afghani ","AFA",26813057,"Afghanistan",""
2,"Albania","AL","AL","ALB","8","AL","Tirana ","Europe ","Albanian","Albanians","Lek ","ALL",3510484,"Albania",""

State (Region File)

"RegionId","CountryId","Region","Code","ADM1Code"
1,14,"Victoria","VI","AS07"
2,14,"Tasmania","TS","AS06"
3,14,"Queensland","QL","AS04"
4,14,"New South Wales","NS","AS02"

City

"CityId","CountryID","RegionID","City","Latitude","Longitude","TimeZone","DmaId","Code"
42231,1,833,"Herat","34.333","62.2","+04:30",0,"HERA"
5976,1,835,"Kabul","34.517","69.183","+04:50",0,"KABU"
42230,1,852,"Mazar-e Sharif","36.7","67.1","+4:30",0,"MSHA"
42412,2,983,"Korce","40.6162","20.7779","+01:00",0,"KORC"
5977,2,1011,"Tirane","41.333","19.833","+01:00",0,"TIRA"

我已将数据导入三个单独的集合中,但我不确定这将是最好的前进方式。由于城市数据集非常大,我希望能够过滤国家/州/省,最后只是那里的城市。

关于我应该怎么做的任何建议都会很棒。

1 个答案:

答案 0 :(得分:0)

如果您计划在移动设备或慢速连接上使用此应用,请注意以下几点: 1)注意您在订阅中包含的内容。您不希望或不需要客户端上的这整个数据集。您可能根本不想订阅这些数据。 2)你提到过滤。 Meteor(以及MongoDB)不会自动添加索引。因此,如果您知道您将按CountryID或RegionID过滤城市,那么您需要自己设置索引。

我认为您正在采用最佳方法来表示Mongo / Meteor中的数据。您绝对不希望有一个名为“地点”的集合,其中包含具有“子城市”子列表的“具有区域”子列表的国家/地区。

但是,您是否有任何理由需要自己主持?听起来像是一场噩梦,因为新的城市和地区经常被添加。你能用第三方服务吗?这将允许您直接从客户端调用或执行服务器端缓存。然后,您可以允许该服务处理过滤功能/复杂性。这是第一种我会研究的方法,如果没有经济有效的解决方案,我可以自己主持。