Search code examples
mongodblithiumnosql

Storing Country, State, City and Zip in NoSQL


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?


Solution

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