0

I'm planning a database and I'm considering mongoDB.
My main use would be to cross reference documents in the same collection.
The problem is that I didn't find any simple way to do it except for mapreduce.
Is there any simple way to do it?
For example, I have documents which represent countries and each country contains an array of cities, and I would like to get a list of all countries which have cities with the same name in them. Is it possible in a simple way in mongo (or any other noSQL db) or should I use sql?

Thanks!

  • yes it is possible through mongoDB – Ganesh Karamala Jan 06 '16 at 08:45
  • http://stackoverflow.com/questions/32197603/storing-country-state-city-in-mongodb https://groups.google.com/forum/#!topic/mongodb-user/tRmY09ZxGDA – Ganesh Karamala Jan 06 '16 at 08:57
  • Thanks @GaneshKaramala can you explain how is it possible or provide a link to where I can read about it? – John Rich Jan 06 '16 at 08:57
  • You can use the aggregation framework in MongoDB for this, see https://docs.mongodb.org/manual/core/aggregation-introduction/. You can use `$unwind` to unwind the cities array inside each country and then use a $group operator to find cities that occur more than one times. You can `$push` the countries in an array, so you get a document per city containing all the countries this city exists in. – Alex Jan 06 '16 at 09:22
  • Possible duplicate of [MongoDB normalization, foreign key and joining](http://stackoverflow.com/questions/5841681/mongodb-normalization-foreign-key-and-joining) – Paul Sweatte Aug 16 '16 at 14:47

0 Answers0