在MongoDB存储国家城市 [英] Storing country state city in MongoDB

查看:333
本文介绍了在MongoDB存储国家城市的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在建立数据库来存储国家 - 城市信息,这些信息将在我们网站的下拉菜单中使用。

I am currently working on building database to store country-state-city information which is later to be used from drop down menus in our website.

我想对于我已经决定如何有效地运行的模式,几乎没有建议。

I wanted to get few suggestions on the schema that I have decided as to how efficiently it will work.

我正在使用MongoDB来存储数据。

I am using MongoDB to store the data.

我设计的模式如下:

{
_id: "XXXX",
country_name: "XXXX",
some more fields
state_list:[
    {
        state_name: "XXXX",
        some more fields
        city_list:[
            {
                city_name : "XXXX",
                some more fields
            },
            {
                city_name : "XXXX",
                some more fields
            }

        ]

    }
]

}

数据将会增加。每个州也有很长的城市名单。

The data will be increasing. Also there is a long list of cities for each state.

该模式对于预期目的有多好?

How good this schema will work for the intended purpose?

我应该使用链接文档技术需要手动编码来映射_id)?

Should I use linking documents technique (this will require manual coding to map the _id) ?

推荐答案

我认为随着数据的增加,这种架构将会崩溃。最好的方法是以3种模式打破数据库,并使用其IDs的引用。

I think as your data will increase , this schema will collapse. The best way is to break the database in 3 schemas and use refrence of their Ids.

国家模式:

{
_id: "XXXX",
country_name: "XXXX",
some more fields
state_list:[{
  "_id": reference id to state object
}]
}

状态模式:

{
 _id: "XXXX",
 state_name: "XXXX",
 some more fields
 city_list:[{
   "_id" : reference to city object
 }]
}

城市模式:

{
 _id: "XXXX",
 city_name: "XXXX",
 some more fields

}

这篇关于在MongoDB存储国家城市的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆