Storing country state city in MongoDB

2,526 views
Skip to first unread message

Suhas Shelar

unread,
Aug 25, 2015, 6:37:17 PM8/25/15
to mongodb-user

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.

I am using MongoDB to store the data.

The schema that I have designed is as follows:

{
_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?

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

Asya Kamsky

unread,
Aug 26, 2015, 12:06:29 PM8/26/15
to mongod...@googlegroups.com
Which is better depends on how you will be using this data, but I'm certain that the way you propose is only good if you ever query for entire country document, it is not likely to be good for other types of reads/writes. 

You mention linking - have you considered demoralizing instead?

For example, you can have a collection of cities where each city includes the state and country (indexed of course) and the state and country attributes that you need all the time (and which are immutable, hopefully or at least changed infrequently)

But let us know how you will be reading and writing this data as that will likely suggest which schema would be the best. 

Asya
--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/39a7a453-cf5b-46ac-9d88-7379c99677c0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

durg...@gmail.com

unread,
Mar 7, 2018, 4:28:39 PM3/7/18
to mongodb-user
Hello Sir ,
 can you provide me MVC4 source code for all binding country, state,city dropdownlist  
Reply all
Reply to author
Forward
0 new messages