Monday, April 20, 2015

M102: MongoDB for DBAs - week 5 answer

Homework 5.1

1) 7

Homework 5.2

Check on 

1) Add an arbiter.
2) Add another data bearing node

Homework 5.3

db.m102.insert([{"a":1},{"b":2},{"c":3}])

Homework 5.4

Check on None of the above.

Homework 5.5

{ force : true }


Monday, April 13, 2015

M102: MongoDB for DBAs - Homework 4.2


Step 1:
You need to run all the replica Set use below command
mongod --dbpath "c://1" --replSet abc --port 27002
mongod --dbpath "c://2" --replSet abc --port 27002
mongod --dbpath "c://3" --replSet abc --port 27003

Step 2:
Note: do close mongo shell, if you have close then reload the data as per step given in homework 4.1

Step 3:
Run on mongo shell
rs.initiate()
then
use replication
then db.foo.find() to check data

then run

homework.b()
you will get your answer as 5002



Saturday, April 11, 2015

Answer For Week 4 for mongodb

All the Answer for week 4 mongodb 102 course                            

1) Homework 4.1 :  answer is 5001
2) Homework 4.2: answer is  5002
3) Homework 4.3: answer is 5
4) Homework 4.4 : answer is 6
5) Homeowrk 4.5 : answer is R

M102: MongoDB for DBAs : Homework 4.1

Step 1:
Download Handout

Step 2:
Unpack replication.js from the Download Handout zip file.

Step 3:
You need to create 3 different directory for 3 replica set

on windows:
you can create diretory as 1 , 2 and 3 in c drive

you can start mongod instance using
mongod --dbpath 1 --port 27001 --smallfiles --oplogSize 50


Step 4:
you can import replication.js using

mongo --port 27001 --shell replication.js


Step 5:
Once the shell is up
you can write
homework.init();

then homework.a();


Above query will give your answer as
5001


Tuesday, April 7, 2015

M102: MongoDB for DBAs - homework 3.4

Wiredtiger is new storage engine, it come with following feature
1) Data compression
2) Document level locking.

Monday, April 6, 2015

M102: MongoDB for DBAs - Homework 3.3

Step 1:
Download the handout


Step 2:
import products.json using mongo import utility


mongoimport -d pcat -c products --drop products.json

Step 3:
now enter into mongo shell 
use pcat database using 
use pcat

Step 4:
add index on for field using 
db.products.ensureIndex({for:1});

Step 5:
now create and run the query you will  get answer as

q1) 4
q2) 4
q3) yes

M102: MongoDB for DBAs - Homework 3.2

Step 1:
In mongo shell run
homework.b()

operation will be very slow, you need to figure out the same

Step 2:
open another prompt
type below command in command prompt
 mongo --shell localhost/performance performance.js

note: do not close first shell

Step 3:
Using db.currentOp() you can check current running operation and using
db.killOp(?) you can kill the running operation

? - will be operation id
{ opid}

step 4:
now run homework.c()

you will get your answer as 12

M102: MongoDB for DBAs - Homework 3.1

Step 1:
Download the handout and load in mongodb using

mongo --shell localhost/performance performance.js


then run

homework.init()


you need to add index on field
active and timestamp

Step 2:
Add Index using

db.sensor_readings.ensureIndex({tstamp:1, active:1})

Step 3:
run homework.a()

you will get answer as 6

if anything wrong you will get a message to try better index

Sunday, March 29, 2015

M102: MONGODB FOR DBAS - Homework 2.3

Step 1:
execute below query in mongo shell
> db.products.find({"limits.voice":{$exists:1}}).count()

you will get your answer as 3

M102: MONGODB FOR DBAS - Homework 2.2


Step 1:
Now you need to add product in products collection

you  need to update the id
_id : ObjectId("507d95d5719dbef170f15c00")


with following

term_years to  3
over_rate  for sms in limits to 0.01 from 0


Execute below Query in mongoshell

var temp = db.products.findOne({_id:ObjectId("507d95d5719dbef170f15c00")})

temp.term_years = 3

db.products.update({_id:temp._id},temp)

temp.limits.sms.over_rate = 0.01

db.products.update({_id:temp._id},temp)








Check your answer:

by executing homework.b()

you will get your answer as
0.050.019031


M102: MONGODB FOR DBAS - homework 2.1

Step 1:
Download the handout from

you will see homework2.js








Step 2:
import homework2.js
using
mongo --shell pcat homework2.js

Step 3:
on mongo shell type
>homework.a()

you will get your answer as 3.05


M102: MONGODB FOR DBAS - Homework 1.4

Step 1:
Check all the query in mongodb shell

Step 2:
you will observe that it is giving sorted result for


M102: MONGODB FOR DBAS HOMEWORK - HOMEWORK 1.3

Step 1:
> use pcat

Step 2:
> db.products.find({'brand':'ACME'})


Saturday, March 28, 2015

M102: MongoDB for DBAs - Week 1 - Homework 1.2

Step 1:

Download the products.json

Step 2:

Import products.json using below command
mongoimport -d pcat -c products --type json --file C:\products.json





Step 3:

execute below steps
> use pcat
> db.products.find({type:"case"}).count()

Answer you will get is 3


M102: MongoDB for DBAs homework 1.1

Step 1:
Execute Mongo  Command   db.isMaster().maxBsonObjectSize in shell
you will get output as


Answer is 16777216

Sunday, January 25, 2015

M101JS: MongoDB for Node.js Developers Homework 2.2

Step 1:
you need to download mongoproc

Step 2:
you need to find  a document with highest recorded temperature for each state and adds a "month_high" field for that document and set its value as true.

Solution:
well i did manually and haven't write a  program

you need to find highest recorded temperature for each state.

so first get distinct of each state, using
>db.data.distinct('State');

then using
> db.data.find({ State: "Vermont"}).sort({ Temperature : -1}).limit(1)

get the _id assoicated with it and plly with update query

> db.data.update({ "_id" : ObjectId("54c48c740831934d31102f02") }, { $set : { "month_high" : true }});


do this for all state and then

on mongoproc test your result if it sucess then submit your answer





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





M101JS: MongoDB for Node.js Developers - Week 2

hi friends,
i will start with week 2 introduction.

Week 2 of of m101js is related with CRUD operation of mongodb. you will learn following things
  1. Mongo Shell
  2. BSON
  3. Insert Operation
  4. find
  5. Field Selection
  6. various operator like $gt, $lt,regex,$or,$and,$set,$unset
  7. upserts
  8. multiupdate
  9. removing data
  10. Above Operation with node.js

Friday, January 23, 2015

M101JS: MongoDB for Node.js Developers Homework 1.3

M101JS: MongoDB for Node.js Developers Homework 1.3


Step 1:
Download the homework 1.3 material

Step 2:
Untar or unzip the material

Go to To unzip path
C:\Users\Downloads\hw1-3.607f73fdd4fc\hw1-3

Step 3:
type command> mongorestore dump

Step 4:
on unix:
install driver of node.js for mongodb

npm install mongodb

for windows:
http://nodejs.org/#download

Now Run The application.

node app.js


you will get your answers
Hello, Agent 007.

M101JS: MongoDB for Node.js Developers - Homework 1.2

M101JS: MongoDB for Node.js Developers - Homework 1.2  

Step 1:
Download the homework 1.2 material

Step 2:
Untar or unzip the material

Go to To unzip path
C:\Users\Downloads\hw1-2.92b836706307\hw1-2

Step 3:
type command> mongorestore dump

Step 4:
on unix:
install driver of node.js for mongodb

npm install mongodb

for windows:
http://nodejs.org/#download

Now Run The application.

node app.js


you will get your answers
I like kittens

M101JS: MongoDB for Node.js Developers - Homework 1.1

M101JS: MongoDB for Node.js Developers

HomeWork 1.1: you need to import handout material using mongo restore

  • Download the HomeWork Material.
  • unzip or untar the above folder
  • go to terminal or cmd with unzip path 
  • type mongorestore dump
  • note: dump is  folder name
  • after running the command you will upload all the bson data into mongo.
Now To validate your answer type in cmd:
>  use hw1_1
> db.hw1_1.findone()
>Output:

{
        "_id" : ObjectId("51e4524ef3651c651a42331c"),
        "answer" : "Hello from MongoDB!"
}

so your first week answer is

 Hello from MongoDB!