开发者

Storing Country, State, City and Zip in NoSQL

开发者 https://www.devze.com 2023-04-05 01:15 出处:网络
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.

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?


I think your schema is okay in mongo you can index array fields for perf and query subdocuments and partial arrays with $slice.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消