[Solution] Week 3 :The Node.js Driver : M101JS: MongoDB for Node.js Developers
Homework 3.1 :
Solution :
Homework 3.2 :
{"_id": 1, "student": "Mary", "grade": 45, "assignment": "homework"} {"_id": 2, "student": "Alice", "grade": 48, "assignment": "homework"} {"_id": 3, "student": "Fiona", "grade": 16, "assignment": "quiz"} {"_id": 4, "student": "Wendy", "grade": 12, "assignment": "homework"} {"_id": 5, "student": "Samantha", "grade": 82, "assignment": "homework"} {"_id": 6, "student": "Fay", "grade": 89, "assignment": "quiz"} {"_id": 7, "student": "Katherine", "grade": 77, "assignment": "quiz"} {"_id": 8, "student": "Stacy", "grade": 73, "assignment": "quiz"} {"_id": 9, "student": "Sam", "grade": 61, "assignment": "homework"} {"_id": 10, "student": "Tom", "grade": 67, "assignment": "exam"} {"_id": 11, "student": "Ted", "grade": 52, "assignment": "exam"} {"_id": 12, "student": "Bill", "grade": 59, "assignment": "exam"} {"_id": 13, "student": "Bob", "grade": 37, "assignment": "exam"} {"_id": 14, "student": "Seamus", "grade": 33, "assignment": "exam"} {"_id": 15, "student": "Kim", "grade": 28, "assignment": "quiz"} {"_id": 16, "student": "Sacha", "grade": 23, "assignment": "quiz"} {"_id": 17, "student": "David", "grade": 5, "assignment": "exam"} {"_id": 18, "student": "Steve", "grade": 9, "assignment": "homework"} {"_id": 19, "student": "Burt", "grade": 90, "assignment": "quiz"} {"_id": 20, "student": "Stan", "grade": 92, "assignment": "exam"}Assuming the variable db holds a connection to the school database in the following code snippet.
var cursor = db.collection("grades").find({}); cursor.skip(6); cursor.limit(2); cursor.sort({"grade": 1});Which student's documents will be returned as part of a subsequent call to toArray()?
Solution :
Answer : Seamus,Bob
Homework 3.3 :
To import a fresh version of the companies.json data, please type the following:
mongoimport --drop -d crunchbase -c companies companies.json
If you have already mongoimported this data you will first need to drop the crunchbase database in the Mongo shell. Do that by typing the following two commands, one at a time, in the Mongo shell:
use crunchbase db.dropDatabase()
The code in the attached handout is complete with the exception of the queryDocument() function. As in the lessons, the queryDocument() function builds an object that will be passed to find() to match a set of documents from the crunchbase.companies collection.
For this assignment, please complete the queryDocument() function as described in the TODO comments you will find in that function.
Once complete, run this application by typing:
node buildingQueryDocuments.js
When you are convinced you have completed the application correctly, please enter the average number of employees per company reported in the output. Enter only the number reported. It should be three numeric digits.
As a check that you have completed the exercise correctly, the total number of unique companies reported by the application should equal 42.
Solution :
function queryDocument(options) { var query = { "tag_list": {"$regex": "social-networking"}, }; if (("firstYear" in options) && ("lastYear" in options)) { query.founded_year = { "$gte": options.firstYear, "$lte": options.lastYear }; } else if ("firstYear" in options) { query.founded_year = { "$gte": options.firstYear }; } else if ("lastYear" in options) { query.founded_year = { "$lte": options.lastYear }; } if ("city" in options) { query["offices.city"] = options.city; } return query; }Answer : 169
Homework 3.4 :
In completing this exercise, you will find the "Logical Operators" lesson from Chapter 2 of this course helpful as a refresher on the $or operator.
This application depends on the companies.json dataset distributed as a handout with the "find() and Cursors in the Node.js Driver" lesson. You must first import that collection. Please ensure you are working with an unmodified version of the collection before beginning this exercise.
To import a fresh version of the companies.json data, please type the following:
mongoimport --drop -d crunchbase -c companies companies.jsonIf you have already mongoimported this data you will first need to drop the crunchbase database in the Mongo shell. Do that by typing the following two commands, one at a time, in the Mongo shell:
use crunchbase db.dropDatabase()The code attached is complete with the exception of the queryDocument() function. As in the lessons, the queryDocument() function builds an object that will be passed to find() to match a set of documents from the crunchbase.companies collection.
For this assignment, please complete the queryDocument() function as described in the TODO comments you will find in that function.
Once complete, run this application by typing:
node overviewOrTags.jsWhen you are convinced you have completed the application correctly, please enter the average number of employees per company reported in the output. Enter only the number reported. It should be two numeric digits.
As a check that you have completed the exercise correctly, the total number of unique companies reported by the application should equal 194.
If the grading system does not accept the first solution you enter, please do not make further attempts to have your solution graded without seeking some help in the discussion forum.
Solution :
function queryDocument(options) {
var query = {};
if ("overview" in options) {
query["$or"] = [
{"overview": {"$regex": options.overview, "$options": "i"}},
{"tag_list": {"$regex": options.overview, "$options": "i"}}
];
}
if ("milestones" in options) {
query["milestones.source_description"] =
{"$regex": options.milestones, "$options": "i"};
}
return query;
}
Answer : 48Enjoy....!!!!
Feel free to comment below your experience with above approach and If you still find any problem with above steps Let me know I would love to help you to resolve your problem.
If you want to take your Technological Knowledge to the Next Level and For More Technological information Stay tuned to Visionfortech
Related Post :
1) [SOLUTION] WEEK 1 : INTRODUCTION : M101JS: MongoDB for Node.js Developers2) [SOLUTION] WEEK 2 : CRUD : M101JS: MongoDB for Node.js Developers
3) [SOLUTION] Week 3 :The Node.js Driver : M101JS: MongoDB for Node.js Developers
4) [SOLUTION] WEEK 4 : SCHEMA DESIGN : M101JS: MongoDB for Node.js Developers
5) [SOLUTION] WEEK 5 : INDEXES AND PERFORMANCE : M101JS: MongoDB for Node.js Developers
6) [SOLUTION] WEEK 6 : THE AGGREGATION FRAMEWORK : MongoDB for Node.js Developers
7) [SOLUTION] WEEK 7 :APPLICATION ENGINEERING : MongoDB for Node.js Developers
8) [SOLUTION] FINAL EXAM(PROJECT) :MONGOMART APPLICATION : M101JS: MongoDB for Node.js Developers
Excellent blog.I really like your article. You’ve mentioned steps which can be easily understood.The person who created this post is a genius and knows how to keep the readers connected.Have a look on Yiioverflow ,if you want any software solutions.we bring to you the BEST solutions at nominal rates.
ReplyDeleteQuery for problem 5.3 - db.profile.find({ns:"school2.students"}).sort({millis:-1}).limit(1).pretty()
ReplyDelete