Saturday, January 24, 2015

M101JS: MongoDB for Node.js Developers - Homework 2.1

M101JS: MongoDB for Node.js Developers - Homework 2.1

Step 1:
Download Homework material

Step 2:
Import Weather Data using 
mongoimport --type csv --headerline weather_data.csv -d weather -c data

Step 3:
Validate your data using 
> use weather
> db.data.find().count();
> 2963


Step 4:
Question:
you need to find the state  that recorded the lowest temperature when the wind was coming from the west. (wind direction from 180 to 360). you need to get the name of the state.

Solution:
1) you need to first find the record that has wind direction between 180 to 360.
Query : { "Wind Direction":{$gte:180,$lte:360}}

> db.data.find({ "Wind Direction":{$gte:180,$lte:360}})


now we need to sort to find the lowest temperature, so you need to add sort in ascending order.

so add .sort({ Temperature : 1}) to above query.

so final query will be

> db.data.find({ "Wind Direction" : { $gte : 180, $lte : 360}}).sort({ Temperature : 1})

now in the first row you can look for the state
you will get your answer as

New Mexico





No comments:

Post a Comment