M220J MongoDB for Java Developers ALL Quiz Answers

Let’s discuss MongoDB University Course M220J – MongoDB for Java Developers Chapter 1 – Driver Setup Quiz Answer with you..

Chapter 1 – Driver Setup Quiz Answer

 
 
  

Given the following MongoDB URI:

mongodb+srv://brigitte:[email protected]/admin
 
which of the following statements is true ?
 
  • There are 1234 nodes in the xyz Replica Set
  • The password used to authenticate is bardot
  • The user bardot is trying to authenticate on database admin
  • The server xyz-1234.srv.net is a member of the Replica Set the user
    is trying to connect to
 

MongoClient

Which of the following class names are part of the basic MongoDB Java driver objects ?
  • Document
  • MongoClient
  • Database
  • MongoCollection
 
 
 

Driver Connection

What utility does the MongoClients class provide?
  • A builder method to generate a MongoClient instance.
  • A List of MongoClient instances that are ready to be used
  • An automatic factory of configuration settings to connect to our
    server.
 
 
 

Compass Basics

Use Compass to find which film title in the movies collection is 31st result document of all films that came out in 1991, when sorted by title in order 1 (ascending).
 
To complete this task check out the $skip option for your pipeline.
  • “Cape Fear”
  • “100 Days”
  • “Bad Karma”
  • “Autobus”
 
 

Query Builders

Select the true statements below
  • You can combine Filters to compose robust queries.
  • Filters and Projections are the only available Builders
    classes.
  • Filters and Projections do not offer full query and projection
    functionality.
  • Projections offers a convenience method, excludeId(), to remove the
    _id field in a projection.
 
 

Basic Reads

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

Using POJO – Part 2

Imagine you have a date field in the Document that contains a Date data type in it and a Java Object where the date property is a String type. How would you read this Document into the Java Object while gaining the ability to also write to the Document form the Java Object.
  • Using a manual mapping method
  • Using a POJO in conjunction with a Default Codec
  • Using a POJO in conjunction with a Custom Codec
  • Using a POJO with a Default Codec and a custom field type conversion
    script

MongoDB for Java Developers

Chapter 2 – User-Facing Backend Quiz Answer

 
Let’s go through sample MongoDB University Course M220J – MongoDB for Java Developers Chapter 2 – User-Facing Backend Quiz Answer with you..
 

Complex Aggregations

Which of the following classes can be used to compose aggregation
pipeline stages and expressions ?
  • com.mongodb.client.model.Filters
  • com.mongodb.client.model.Aggregates
  • com.mongodb.client.model.Accumulators

Basic Writes – Updates

What is true about the Document Object inserted into a collection using
the insertOne method?
  • It is a cursor.
  • It contains the _id of an inserted document even if the Document
    did not have an _id value prior to insertion.
  • It can tell us whether the operation was acknowledged by the server.

Write Concerns

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

Update Operators

When changing a field value in a single document it is best to use
  • deleteOne
  • replaceOne
  • updateOne
  • updateMany

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 about deleting documents using the MongoDB Java Driver?
  • deleteOne can only delete one document.
  • deleteOne will not return a DeleteResult object.
  • deleteMany can delete any number of documents.
  • MongoDB Java Driver can only delete one document at a time.
  • DeleteResult objects contain the number of deleted
    documents.

 

 

Chapter 3 – Admin Backend Quiz Answer

 
Let’s practice about MongoDB University Course M220J – MongoDB for Java Developers Chapter 3 – Admin Backend Quiz Answer with you..
 
 
 

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 Quiz Answer

 
Now time to practice  MongoDB University Course M220J – MongoDB for Java Developers Chapter 4 – Resiliency Quiz & Answer.
 

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 issuing bulk operations in large
    batches.
  • When our application is using a Write Concern more durable than
    w: 1.
  • 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?
  • 7
  • 5
  • 1
  • majority
 
 

Change Streams

What of the following is true about Change Streams?
  • They can stay open for up to 10 minutes.
  • They can be used to log changes to a MongoDB collection.
  • They will not log changes associated with insert operations.
  • They output cursors, which contain change event documents.
  • They accept pipelines, which can be used to filter output from the
    change stream.

 

 

Final Exam Quiz Answer

 
Let’s practice MongoDB University Course M220J – MongoDB for Java 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?
 
 
Bson query = gte(“winner_electoral_votes”, 160);
 
Bson query = and(eq(“winner_party”, “Republican”),

lt(“winner_electoral_votes”, 160));
 
Bson query = and(eq(“winner_party”, “Republican”),

lte(“winner_electoral_votes”, 160));
 
Bson query = and(eq(“winner_party”, “Republican”),

gte(“winner_electoral_votes”, 160));
 
Bson query5 = and(gte(“total_electoral_votes”, 160),
              eq(“winner_party”,
“Republican”));
 
 
 
 
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?
 
Bson query = lte(“software_version”, 4.0);
Bson modification = set(“needs_to_update”, true);
phonesCollection.updateMany(query, modification);
 
Bson query = lt(“software_version”, 4.0);
Bson modification = set(“needs_to_update”, true);
phonesCollection.updateOne(query, modification);
 
Bson query = gt(“software_version”, 4.0);
Bson modification = set(“needs_to_update”, true);
phonesCollection.updateMany(query, modification);
 
Bson query = lt(“software_version”, 4.0);
Bson modification = inc(“needs_to_update”, true);
phonesCollection.updateMany(query, modification);
 
Bson query = lt(“software_version”, 4.0);
Bson modification = set(“needs_to_update”, true);
phonesCollection.updateMany(query, modification);
 
 
 
Question 3)
Let’s take the following code, where URI is a connection to your Atlas cluster using an SRV record.
 
MongoClientSettings settings = MongoClientSettings.builder() \
    .applyConnectionString(new
ConnectionString(URI)).build();
MongoClient mongoClient = MongoClients.create(settings);
 
// TODO do a read on the cluster to ensure you are connected
 
SslSettings sslSettings = settings.getSslSettings();
ReadPreference readPreference = settings.getReadPreference();
ReadConcern readConcern = settings.getReadConcern();
WriteConcern writeConcern = settings.getWriteConcern();
 
 
Which of the following variables contained the associated value?
  • readPreference.toString() = “primary”
  • sslSettings.isEnabled() = false
  • sslSettings.isInvalidHostNameAllowed() = true
  • writeConcern.asDocument().toString() = “{ w : 1 }”
  • readConcern.asDocument().toString() = “{ }”
 
 
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 code, doing a bulkWrite to an empty collection
called employees:
 
MongoClient mongoClient = MongoClients.create(URI);
MongoDatabase db = mongoClient.getDatabase(DATABASE);
MongoCollection employeesCollection =

db.getCollection("employees");
 
Document doc1 = new Document("_id", 11)

.append("name", "Edgar Martinez")

.append("salary", "8.5M");
Document doc2 = new Document("_id", 3)

.append("name", "Alex Rodriguez")

.append("salary", "18.3M");
Document doc3 = new Document("_id", 24)

.append("name", "Ken Griffey Jr.")

.append("salary", "12.4M");
Document doc4 = new Document("_id", 11)

.append("name", "David Bell")

.append("salary", "2.5M");
Document doc5 = new Document("_id", 19)

.append("name", "Jay Buhner")

.append("salary", "5.1M");
 
List<WriteModel> requests = Arrays.asList(

new InsertOneModel<>(doc1),

new InsertOneModel<>(doc2),

new InsertOneModel<>(doc3),

new InsertOneModel<>(doc4),

new
InsertOneModel<>(doc5));
try {
    employeesCollection.bulkWrite(requests);
} catch (Exception e) {
    System.out.println("ERROR: " + e.toString());
}
 
Which of the insert operations in requests will succeed?
 
  • Insert of doc1
  • Insert of doc2
  • Insert of doc3
  • Insert of doc4
  • Insert of doc5
 
 
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.
 
If after 30 seconds, the client still cannot connect to a new primary;
which of the following exceptions will be raised by the Java Driver?
  • com.mongodb.MongoServerException
  • com.mongodb.MongoTimeoutException
  • org.bson.BsonInvalidOperationException
  • com.mongodb.MongoConfigurationException
  • com.mongodb.MongoCursorNotFoundException

 

 
 
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 represented by the coll
object?
    • coll.find().sort(orderBy(descending(“height”))).skip(3).limit(2)
    • oll.find().sort(orderBy(descending(“height”))).skip(5).limit(3)
    • coll.find().sort(orderBy(descending(“height”))).limit(5).skip(3)
    • coll.find().sort(orderBy(descending(“height”))).skip(3).limit(5)

Leave a Comment