0

i'm new in NoSQL and i like how it work but i have some difficulties to think NoSQL. i want to do a place referential with multiple layers : - Country - City - Place

It is hard to don't think as a relational database. So what is the NoSQL strategy ? My first approach is to create a table named "place" with this format :

{
   placename: String,
   placelongitude: Number,
   placelatitude: Number,
   placeparent: String
}

But i think this is not the best way for NoSQL. i have think about this way :

{
   countryname: String,
   cities: [{
      cityname: String,
      places: [{
         placeid: Number,
         placename: String,
         placelongitude: Number,
         placelatitude: Number
      }],
   }]
}

What do you think ? Thanks for help.

Community
  • 1
  • 1
Pred05
  • 492
  • 1
  • 3
  • 13

1 Answers1

1

Store places in your collection with city and country as keys

{
    placeid: Number,
    placename: String,
    placelongitude: Number,
    placelatitude: Number,
    cityname: String,
    countryname: String
}
hyades
  • 3,110
  • 1
  • 17
  • 36
  • Oh ok, but the repetition is not a problem ? And if i want to add some fields in my city or country like size or other, i will have to repeat this information to ? Or i can put the cityname with city's identifier to get the rest of information if i need to have it ? – Pred05 Apr 01 '16 at 20:29
  • Yea thats a trade off in using a document based DB. Your reads become much faster, but since data is not normalized your update performance isnt great. – hyades Apr 01 '16 at 20:34
  • Ok it is clearer thanks, i will try. – Pred05 Apr 01 '16 at 20:42