Following are presented the contents and answers to the HomeWorks belonging to Week 1 (Introduction) for “M101JS: MongoDB for Node.js Developers” course offered by https://university.mongodb.com/ started at 2014-03-24.
HOMEWORK 1.1
ANSWER HOMEWORK 1.1:
Simply it was about verifying the correct MongoDB installation, example data import and basic query execution over those imported data.
First, mongorestore:
1
2
3
4
5
6
7
$ /opt/mongodb-linux-i686-2.6.0/bin/mongorestore
connected to: 127.0.0.1
2014-05-07T07:49:22.176-0500 dump/m101/hw1_1.bson
2014-05-07T07:49:22.176-0500 going into namespace [m101.hw1_1]
1 objects found
2014-05-07T07:49:22.178-0500 Creating index: { key: { _id: 1 }, ns: "m101.hw1_1", name: "_id_" }
$
Then, some MongoShell checks about the restoration and the result answer:
MongoDB shell version: 2.6.0
connecting to: test
Server has startup warnings:
2014-05-07T07:48:32.639-0500 [initandlisten]
2014-05-07T07:48:32.639-0500 [initandlisten] ** NOTE: This is a 32 bit MongoDB binary.
2014-05-07T07:48:32.639-0500 [initandlisten] ** 32 bit builds are limited to less than 2GB of data (or less with --journal).
2014-05-07T07:48:32.639-0500 [initandlisten] ** Note that journaling defaults to off for 32 bit and is currently off.
2014-05-07T07:48:32.639-0500 [initandlisten] ** See http://dochub.mongodb.org/core/32bit
2014-05-07T07:48:32.640-0500 [initandlisten]
> show dbs
admin (empty)
blog 0.078GB
enron 0.953GB
final7 0.078GB
local 0.078GB
school 0.078GB
test 0.078GB
weather 0.078GB
> show dbs
admin (empty)
blog 0.078GB
enron 0.953GB
final7 0.078GB
local 0.078GB
m101 0.078GB
school 0.078GB
test 0.078GB
weather 0.078GB
> use m101
switched to db m101
> show tables
hw1_1
system.indexes
> db.hw1_1.count()
1
> db.hw1_1.findOne()
{
"_id" : ObjectId("51e4524ef3651c651a42331c"),
"answer" : "Hello from MongoDB!"
}
>
HOMEWORK 1.2
ANSWER HOMEWORK 1.2:
HOMEWORK 1.3
ANSWER HOMEWORK 1.3:
Week 2: CRUD
Following are presented the contents and answers to the HomeWorks belonging to Week 2 (CRUD) for “M101JS: MongoDB for Node.js Developers” course offered by https://university.mongodb.com/ started at 2014-03-24.
this.validateLogin=function(username,password,callback){"use strict";// Callback to pass to MongoDB that validates a user documentfunctionvalidateUserDoc(err,user){"use strict";if(err)returncallback(err,null);if(user){if(bcrypt.compareSync(password,user.password)){callback(null,user);}else{varinvalid_password_error=newError("Invalid password");// Set an extra field so we can distinguish this from a db errorinvalid_password_error.invalid_password=true;callback(invalid_password_error,null);}}else{varno_such_user_error=newError("User: "+user+" does not exist");// Set an extra field so we can distinguish this from a db errorno_such_user_error.no_such_user=true;callback(no_such_user_error,null);}}// TODO: hw2.3users.findOne({'_id':username},validateUserDoc);}
Week 3: Schema Design
Following are presented the contents and answers to the HomeWorks belonging to Week 3 (Schema Design) for “M101JS: MongoDB for Node.js Developers” course offered by https://university.mongodb.com/ started at 2014-03-24.
HOMEWORK 3.1
ANSWER HOMEWORK 3.1:
HOMEWORK 3.2
ANSWER HOMEWORK 3.2:
Code snippet for this.insertEntry = function (title, body, tags, author, callback) function:
this.insertEntry=function(title,body,tags,author,callback){"use strict";console.log("inserting blog entry"+title+body);// fix up the permalink to not include whitespacevarpermalink=title.replace(/\s/g,'_');permalink=permalink.replace(/\W/g,'');// Build a new postvarpost={"title":title,"author":author,"body":body,"permalink":permalink,"tags":tags,"comments":[],"date":newDate()}// now insert the post// hw3.2 TODOposts.insert(post,function(err,result){"use strict";if(err)returncallback(err,null);console.log("Inserted new post");callback(err,permalink);});}
Following are presented the contents and answers to the HomeWorks belonging to Week 4 (Performance) for “M101JS: MongoDB for Node.js Developers” course offered by https://university.mongodb.com/ started at 2014-03-24.
HOMEWORK 4.1
ANSWER HOMEWORK 4.1:
HOMEWORK 4.2
ANSWER HOMEWORK 4.2:
HOMEWORK 4.3
ANSWER HOMEWORK 4.3:
HOMEWORK 4.4
ANSWER HOMEWORK 4.4:
Week 5: Aggregation Framework
Following are presented the contents and answers to the HomeWorks belonging to Week 5 (Aggregation Framework) for “M101JS: MongoDB for Node.js Developers” course offered by https://university.mongodb.com/ started at 2014-03-24.
Following are presented the contents and answers to the HomeWorks belonging to Week 6 (Application Engineering) for “M101JS: MongoDB for Node.js Developers” course offered by https://university.mongodb.com/ started at 2014-03-24.
HOMEWORK 6.1
ANSWER HOMEWORK 6.1:
HOMEWORK 6.2
ANSWER HOMEWORK 6.2:
HOMEWORK 6.3
ANSWER HOMEWORK 6.3:
HOMEWORK 6.4
ANSWER HOMEWORK 6.4:
HOMEWORK 6.5
ANSWER HOMEWORK 6.5:
Final Exam
Following are presented the contents and answers to the questions belonging to Final Exam for “M101JS: MongoDB for Node.js Developers” course offered by https://university.mongodb.com/ started at 2014-03-24.
> show dbs
admin (empty)
blog 0.078GB
final7 0.078GB
local 0.078GB
m101 0.078GB
school 0.078GB
test 0.078GB
weather 0.078GB
> show dbs
admin (empty)
blog 0.078GB
enron 0.953GB
final7 0.078GB
local 0.078GB
m101 0.078GB
school 0.078GB
test 0.078GB
weather 0.078GB
> use enron
switched to db enron
> show tables
messages
system.indexes
> db.messages.count()
120477
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$ l
dump/ enron.zip final01_00.js
$ cat final01_00.js
use enron
query = {"headers.From":"andrew.fastow@enron.com", "headers.To":"john.lavorato@enron.com"}
db.messages.find(query).count()
$ /opt/mongodb-linux-i686-2.6.0/bin/mongo < final01_00.js
MongoDB shell version: 2.6.0
connecting to: test
switched to db enron
{
"headers.From" : "andrew.fastow@enron.com",
"headers.To" : "john.lavorato@enron.com"
}
1
bye
$ l
final4/ posts.json
question_4$ cd final4/l
-bash: cd: final4/l: No such file or directory
question_4$ cd final4/
question_4/final4$ l
Final4/ __MACOSX/
question_4/final4$ cd Final4/
question_4/final4/Final4$ l
blog/ validate/
question_4/final4/Final4$ cd validate/
question_4/final4/Final4/validate$ l
final4-validate.js* package.json*
question_4/final4/Final4/validate$ cd ../blog/
question_4/final4/Final4/blog$ l
app.js* package.json* posts.js* README.md* routes/ sessions.js* users.js* views/
question_4/final4/Final4/blog$ cd ../../
question_4/final4$ l
Final4/ __MACOSX/
question_4/final4$ cd ..
question_4$ l
final4/ posts.json
question_4$ /opt/mongodb-linux-i686-2.6.0/bin/mongoimport -d blog -c posts posts.json
connected to: 127.0.0.1
2014-05-08T15:44:37.195-0500 Progress: 34788312/34788312 100%
2014-05-08T15:44:37.195-0500 1000 333/second
2014-05-08T15:44:37.195-0500 check 9 1000
2014-05-08T15:44:37.196-0500 imported 1000 objects
question_4$
> show dbs
admin (empty)
enron 0.953GB
final7 0.078GB
local 0.078GB
m101 0.078GB
school 0.078GB
test 0.078GB
weather 0.078GB
> show dbs
admin (empty)
blog 0.078GB
enron 0.953GB
final7 0.078GB
local 0.078GB
m101 0.078GB
school 0.078GB
test 0.078GB
weather 0.078GB
> use blog
switched to db blog
> show tables
posts
system.indexes
> db.posts.count()
1000
>
1
2
3
blog$ nodejs app.js
Express server listening on port 3000
Found 10 posts
1
2
3
4
5
6
7
8
9
10
11
validate$ l
final4-validate.js* node_modules/ package.json*
validate$ nodejs final4-validate.js
Trying to fetch blog homepage for url http://localhost:3000/
Trying to grab the number of likes for url http://localhost:3000/post/mxwnnnqaflufnqwlekfd
Trying to increment the number of likes for post: /post/mxwnnnqaflufnqwlekfd
Trying to grab the number of likes for url http://localhost:3000/post/mxwnnnqaflufnqwlekfd
Successfully clicked like
Blog validated successfully!
Your validation code is: VQ3jedFjG5VmElLTYKqS
validate$