2
\$\begingroup\$

I am using NodeJS and MongoDB for a weather app that takes the weather info from a logger, saves it to a database, and relays the data to the browser in real-time. It is hosted here with code here which has project details and explanation.

I am saving the weather data to the mongolab cloud-db like so:

// Save to cloud db on MongoLab
mongodb.MongoClient.connect(uri, function (err, cloud_db) {
  cloud_db.collection('raw_data', function(err, collection) {
    if(!err) {
        collection.insert(dbString, function(docs) {
            collection.count(function(err, count) {
                if(!err) {
                    console.log("Saved to mongolab");
                }
            });
        });
     }
  });
});

and the document in db looks like:

{
  "lat": "22.65587",
  "long": "75.82626",
  "date": "2014/08/23",
  "time": "20:10:00.000",
  "temp_c": "25.2",
  "humidity": "86.5",
  "pressure_mbar": "939.0",
  "wind_dir": "85.9",
  "wind_speed_mps": "0.8",
  "rain_mm": "0.0",
  "solar_rad_wpsqm": "-3.8",
  "_id": {
      "$oid": "53f8a7d840ecdfe006b0e3be"
  }
}

I was wondering if this was the best possible schema for storing the data in terms of speed of data retrieval and ease of use.

Another concern is handling the units. I have named the quantities with units in them. Is there any other way this can be handled better ?

\$\endgroup\$
2
\$\begingroup\$

You should probably store the numeric values also as numbers and not as strings. This makes data retrieval and manipulation easier. Also have a look here for the coordinates. Date and time should be one field and conform to the ISO date format so you can easily parse it with JS and all other programming languages.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.