A
A
Arseniy2014-07-27 18:38:59
MongoDB
Arseniy, 2014-07-27 18:38:59

Is the data modeled correctly (MongoDB)?

I am learning mongoDB, I was advised to create a database that shows the weather forecast for 5 cities. The database should be updated 2 times a day. I can’t get used to this paradigm in any way and I am absolutely sure that the structure that I have compiled is not at all optimal. I ask for advice from experienced programmers, how best to fix the structure so that the structure of the database is more optimal, or maybe everything is fine? Thanks in advance.

// Получается какое - то перемешивание
{
  _id : ObjectID(),
  city: rubtsovsk,
  date: 27.07.2014,
  time: 18:30,
  forecast : {
    current_temp_c : 19,
    current_temp_f : 60,
    cloud_title  : "пасмурно",
    precip_title : "без осадков"
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Pavlov, 2014-07-28
@Trytge

First, you must identify the most frequently asked question. Most likely, it is as follows - to find a city by its number (_id) or by name (city), and display the last registered information, and it does not matter when exactly this information was (that is, the time and date will not be included in the query condition). And sometimes you need to display all the available information for the city (for example, in the form of a graph), and then you need the entire collection of data, including information about the date and time.
Then you need this scheme: in the document, keep the last record of the weather. And for history, create an internal collection, into which obsolete data is gradually entered.

{
  _id : ObjectID(),
  city: rubtsovsk,
  forecast : {
    date: 27.07.2014,
    time: 18:30,
    current_temp_c : 19,
    current_temp_f : 60,
    cloud_title  : "пасмурно",
    precip_title : "без осадков"
  },
  forecasts : [
    {
      date: 27.07.2014,
      time: 6:30,
      current_temp_c : 19,
      current_temp_f : 60,
      cloud_title  : "пасмурно",
      precip_title : "без осадков"
    },
    {
      date: 26.07.2014,
      time: 18:30,
      current_temp_c : 19,
      current_temp_f : 60,
      cloud_title  : "пасмурно",
      precip_title : "без осадков"
    }
  ]
}

Plus, I would still replace the string data "overcast", "no precipitation" with their codes, and insert specific lines in the program. At least to take into account the possibility of subsequent localization.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question