在 NoSQL 中存储国家、州、城市和邮政编码
嘿,我正在尝试想出一个好的模式,用于在 NoSQL(MongoDB) 中存储国家/地区、州、城市、邮政编码,并且我希望获得有关该模式的反馈。
{
_id: xxxxx,
country: {
name: "United States",
currency: "USD",
states: {
{
name: "NY"
cites {
"name": Bronx
}
}
}
}
}
基本上我想要的是将一个国家存储为顶层。然后国家有州作为数组,州有城市作为数组,城市有邮政编码数组。请问想法?
Hey I am trying to come up with a good schema for storing country, state, city, zip in a NoSQL(MongoDB) and I wanted from feed back on this schema.
{
_id: xxxxx,
country: {
name: "United States",
currency: "USD",
states: {
{
name: "NY"
cites {
"name": Bronx
}
}
}
}
}
Basically what I was going for was storing a country as a top level. Then countries have states as an array and states has cities as an array and cities will have an array of zip codes. THoughts please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为你的架构在 mongo 中没问题 你可以为 perf 和 使用$slice查询子文档和部分数组。
I think your schema is okay in mongo you can index array fields for perf and query subdocuments and partial arrays with $slice.
实际上,城市不应该有邮政编码数组,因为它们可以跨越城市。相反,我会先有州的邮政编码,然后再有城市的邮政编码。有关详细信息,请参阅本页的最后一个区域:http://www.rierroutes.com/ZIPCodes.html
Actually, cities shouldn't have arrays of zip-codes as those can span across cities. I would instead have zip codes have of states and then cities. See the last area of this page for details: http://www.carrierroutes.com/ZIPCodes.html