M220JS MongoDB for Javascript Developers All Answers

In this article we will discuss MongoDB University | M220JS – MongoDB for Javascript Developers Chapter 0 – Introduction and Setup Quiz and Answer.

Chapter 0 – Introduction and Setup

 
MFlix Application Architecture

During this course, which of the following files in mflix will you have to edit?

 

  • moviesDao.js
  • commentsDao.js
  • server.js
  • comments.controller.js

 

Chapter 1 – Driver Setup

Let’s discuss MongoDB University | M220JS – MongoDB for Javascript Developers Chapter 1 – Driver Setup Quiz Answer with you..
Chapter 1 – Driver Setup Quiz

Asynchronous Programming in Node.js

Select the true statements below.
  • The MongoDB Node driver only supports callbacks.
  • All await statements should be surrounded by a try/catch block.
  • To use the await keyword, the enclosing function must be marked async.
  • If a callback isn’t provided, asynchronous methods in the Node driver will return a Promise.

Basic Reads

Which of the following statements is true regarding reads in MongoDB?
  • The MongoDB Javascript driver can only find one document per query.
  • Field projection is specified as a JSON object.
  • We must explicitly remove the _id field in a projection if we do not want to include this field.

Chapter 2 – User-Facing Backend

 

 

In this article you will go through MongoDB University | M220JS – MongoDB for Javascript Developers Chapter 2 – User-Facing Backend Quiz Answer.
User-Facing Backend Quiz

Cursor Methods and Aggregation Equivalents

Which of the following aggregation stages have equivalent cursor methods?
  • $skip
  • $sort
  • $limit

Basic Writes

Which of the following are valid methods to insert a new document into a collection using the Node.js driver?
  • insertOne
  • insertMany
  • writeDocument
  • updateOne with upsert: true specified in the options.

Write Concerns

Which of the following Write Concerns are valid in a 3-node replica set?
  • w: 0
  • w: 4
  • w: 1
  • w: 5
  • w: majority

Basic Updates

Which of the following can be passed to the updateOne() and updateMany() commands?
  • An update operation
  • An aggregation pipeline
  • An upsert flag
  • A read preference
  • A query predicate

Basic Joins

Why did we use a let expression with expressive $lookup, when joining the comments and the movies collection?
  • To count the number of comments documents.
  • To use fields from the movies documents in the pipeline.
  • To use fields from the comments documents in the pipeline.
  • To store the output of the pipeline in the movie_comments field.

Basic Deletes

Which of the following is true regarding deletes in the Node.js driver?
  • deleteAll deletes all matching documents in a collection.
  • deleteSome deletes some matching documents in a collection.
  • deleteOne deletes the first matching document in $natural order.
  • deleteMany deletes multiple matching documents in one operation.

 

Chapter 3 – Admin Backend

 

 

In this article you will go through MongoDB University | M220JS – MongoDB for Javascript Developers Chapter 3 – Admin Backend Quiz Answer.
Admin Backend Quiz

Read Concerns

Which of the following Read Concerns are valid in a 3-node replica set?
  • “local”
  • 1
  • “majority”
  • 0
  • “nearest”

Bulk Writes

Which of the following is true about bulk writes?
    • By default, bulk writes are ordered.
    • Bulk writes decrease the effect of latency on overall operation time.
    • The server will send one acknowledgement for each write in a bulk operation.
    • If a failure occurs during an ordered bulk write, the server will continue executing the rest of the batch.

 

Chapter 4 – Resiliency

 
In this article we will go through MongoDB University | M220JS – MongoDB for Javascript Developers Chapter 4 – Resiliency Quiz Answer.

Resiliency Quiz

Connection Pooling

Which of the following are benefits of connection pooling?
  • Multiple database clients can share a connection pool.
  • The connection pool will persist after the client is terminated.
  • A large influx of operations can be handled more quickly with a pool of existing connections.
  • New operations can be serviced with pre-existing connections, so a new connection doesn’t have to be created each time.

Robust Client Configuration

When should you set a wtimeout?
  • When our application is using a Write Concern more durable than w: 1.
  • When our application is issuing bulk operations in large batches.
  • When our application is using a connection pool of 100 or more connections.
  • When our application is using a Read Concern more durable than “available”.

Error Handling

Given a replica set with 5 nodes which write concern will cause an error when writing?
    • 5
    • 1
    • 7
    • majority

 

Final Exam Quiz Answer

In this article we will go through MongoDB University | M220JS – MongoDB for Javascript Developers Final Exam Quiz Answer.
Question 1)
Assume a collection called elections that holds data about all United States Presidential Elections since 1789. All the documents in the elections collection look like this:
{
  "year" : 1828,
  "winner" : "Andrew Jackson",
  "winner_running_mate" : "John C. Calhoun",
  "winner_party" : "Democratic",
  "winner_electoral_votes" : 178,
  "total_electoral_votes" : 261
}
total_electoral_votes represents the total number of electoral votes that year, and winner_electoral_votes represents the number of electoral votes received by the winning candidates.
 
Which of the following queries will retrieve all the Republican winners with at least 160 electoral votes?
elections.find( { winner_party: “Republican”,
                    winner_electoral_votes: { “$lt”: 160 } } )
elections.find( { winner_party: “Republican”,
                    total_electoral_votes: { “$lte”: 160 } } )
 elections.find( { total_electoral_votes: { “$gte”: 160 },
                     winner_party: “Republican” } )
 elections.find( { winner_electoral_votes: { “$gte”: 160 } } )
elections.find( { winner_party: “Republican”,
                    “winner_electoral_votes”: { “$gte”: 160 } } )
Question 2)
Consider a collection of phones called phones, used by a phone manufacturer to keep track of the phones currently in production.
Each document in phones looks like this:
{
  "model": 5,
  "date_issued" : ISODate("2016-07-27T20:27:52.834Z"),
  "software_version": 4.8,
  "needs_to_update": false
}
 
There is an update required for phones with software_version earlier than 4.0. Anyone still using a version older than 4.0 will be asked to update.
 
The phone manufacturer wants to set the flag needs_to_update to true when the value of software_version is lower than 4.0. For example, a document like this one:
{
  "model": 5,
  "date_issued" : ISODate("2014-03-04T14:23:43.123Z"),
  "software_version": 3.7,
  "needs_to_update": false
}
 
Should be updated to look like this:
{
  "model": 5,
  "date_issued" : ISODate("2014-03-04T14:23:43.123Z"),
  "software_version": 3.7,
  "needs_to_update": true
}
 
Which of the following update statements will correctly perform this update?
phones.updateMany( { software_version: { “$lt”: 4.0 } },
                    { “$set”: { needs_to_update: True } } )
phones.updateMany( { software_version: { “$lte”: 4.0 } },
                    { “$set”: { needs_to_update: True } } )
phones.updateOne( { software_version: { “$lt”: 4.0 } },
                  { “$set”: { needs_to_update: True } } )
phones.updateMany( { software_version: { “$gt”: 4.0 } },
                    { “$set”: { needs_to_update: True } } )
phones.updateMany( { software_version: { “$lt”: 4.0 } },
                    { “$inc”: { needs_to_update: True } } )
Question 3)
Suppose an instance of MongoClient is created with the following URI string:
import { MongoClient } from "mongodb"
 
const URI = "mongodb+srv://m220-user:[email protected]/test"
 
const testClient = await MongoClient.connect(
  URI,
  {
    authSource: "admin",
    connectTimeoutMS: 50,
    retryWrites: true,
    useNewUrlParser: true
  },
)
 
const clientOptions = testClient.s.options
The variable representing our client, testClient, will:
  • automatically retry writes that fail.
  • use SSL when connecting to MongoDB.
  • authenticate against the test database.
  • allow a maximum of 50 connections in the connection pool.
  • wait at most 50 milliseconds for timing out a connection.
Question 4)
Suppose a client application is sending writes to a replica set with 3 nodes:
Before returning an acknowledgement back to the client, the replica set waits.
 
When the write has been applied by the nodes marked in stripes, it returns an acknowledgement back to the client.
What Write Concern was used in this operation?
  • w: 0
  • w: 1
  • w: available
  • w: majority

 

Question 5)
Given the following bulk write statement, to a collection called employees:
const baseballPlayers = [
  { insertOne: { '_id': 11, 'name': 'Edgar Martinez', 'salary': "8.5M" }},    // Insert #1
  { insertOne: { '_id': 3, 'name': 'Alex Rodriguez', 'salary': "18.3M" }},    // Insert #2
  { insertOne: { '_id': 24, 'name': 'Ken Griffey Jr.', 'salary': "12.4M" }},  // Insert #3
  { insertOne: { '_id': 11, 'name': 'David Bell', 'salary': "2.5M" }},        // Insert #4
  { insertOne: { '_id': 19, 'name': 'Jay Buhner', 'salary': "5.1M" }}         // Insert #5
]
const bulkWriteResponse = employees.bulkWrite(baseballPlayers)
Assume the employees collection is empty, and that there were no network errors in the execution of the bulk write.
 
Which of the insert operations in requests will succeed?
  • Insert #1
  • Insert #2
  • Insert #3
  • Insert #4
  • Insert #5
Question 6)
Suppose a client application is sending writes to a replica set with three nodes, but the primary node stops responding:
Assume that none of the connection settings have been changed, and that the client is only sending insert statements with write concern w: 1 to the server.
 
After 30 seconds, the client still cannot connect to a new primary. Which of the following errors will be thrown by the Node.js driver, and how should it be handled?
  • a Timeout error, resolved by restarting the database server
  • a Duplicate Key error, resolved by using a new _id in the write
  • a Write Concern error, resolved by reducing the durability of the write
  • a Timeout error, resolved by wrapping the call in a try/catch block
  • a Write Concern error, resolved by wrapping the call in a try/catch block
Question 7)
Assume a collection called people_heights with documents that look like this:
{
  "name": "Ada",
  "height": 1.7
}
Which of the following queries will find only the 4th- and 5th-tallest people in the people_heights collection?
  • people_heights.find().sort({ height: -1 }).skip(3).limit(2)
  • people_heights.find().sort({ height: -1 }).skip(3).limit(5)
  • people_heights.find().sort{ height: -1 }).skip(5).limit(3)
  • people_heights.find().sort({ height: -1 }).limit(5).skip(3)

Leave a Comment