C100DBA

C100DBA practice questions, page 2 of 6, with answer review and explanations.

Question 6

Given the following sample documents in the HR collection:{ “name” : “A.S”, “age”: 23, “hobby”: [ “soccer”, “basketball” ]},{ “name” : “B.M”, “age”: 36, “hobby”: [ “soccer”, “baseball” ]},{ “name” : “C.W”, “hobby”: [ “basketball”, “cycling” ]},{ “name” : “R.S”, “age”: 30, “hobby”: [ “soccer”, “cycling”, “baseball” ]},{ “name” : “E.M”, “age”: 25, “hobby”: [ “cycling”, “basketball” ]}What is the output of -db.HR.find( { age: { $in: [ 25, 36] } }, { _id: 0} )

  1. { “name” : “E.M”, “age”: 25, “hobby”: [ “cycling”, “basketball” ]}{ “name” : “R.S”, “age”: 30, “hobby”: [ “soccer”, “cycling”, “baseball” ]}{ “name” : “B.M”, “age”: 36, “hobby”: [ “soccer”, “baseball” ]}
  2. { “name” : “R.S”, “age”: 30, “hobby”: [ “soccer”, “cycling”, “baseball” ]}
  3. { “name” : “B.M”, “age”: 36, “hobby”: [ “soccer”, “baseball” ]}
  4. { “name” : “E.M”, “age”: 25, “hobby”: [ “cycling”, “basketball” ]}
  5. { “name” : “B.M”, “age”: 36, “hobby”: [ “soccer”, “baseball” ]}{ “name” : “E.M”, “age”: 25, “hobby”: [ “cycling”, “basketball” ]}

Question 7

Given the following document:The name is M.M., the date of the exam is May 20, 2022, the subject is Math, and the score is 90.What command will properly add this document to the exams collection?

  1. db.exams.upsertOne( { name: “M.M.”, date: “2022-05-20”, subject: “Math”, score: “90” } )
  2. db.exams.insertOne( { name: “M.M.”, date: new Date (“2022-05-20”), subject: “Math”, score: 90 } )
  3. db.exams.upsertOne( { name: “M.M.”, date: new Date (“2022-05-20”), subject: “Math”, score: 90 } )
  4. db.exams.insertOne( { name: “M.M.”, date: “2022-05-20”, subject: “Math”, score: “90” } )

Question 8

Given the following sample documents:{ _id: 1, firstName: “Person1”, company: “CompanyA”, active: false }{ _id: 2, firstName: “Person2”, company: “CompanyB”, active: false }{ _id: 3, firstName: “Person3”, company: “CompanyC”, active: true }{ _id: 4, firstName: “Person4”, company: “CompanyD”, active: true }What code block should be used to delete the third document from a MongoDB collection in Java?

  1. collection.DeleteOne(eq(“_id”, new ObjectId(3))));
  2. collection.Delete(eq(“_id”, new ObjectId(3))));
  3. collection.Delete(eq(“_id”, 3));
  4. collection.DeleteOne(eq(“_id”, 3));

Question 9

Given the following query generates a collection scan:db.grades.find({“class_id” : 149, “scores.score” : {$gt : 75 }}). sort ({“score.type”:1})Which two indexes improve the performance of the query the most? (Choose two.)

  1. db.grades.createIndex({“scores.type” : 1, class_id : 1, “scores.score” : 1} )
  2. db.grades.createIndex({ “scores.type” : 1, “scores.score” : 1, class_id : 1} )
  3. db.grades.createIndex({class_id : 1, “score.type” : 1, “scores.score” : 1} )
  4. db.grades.createIndex({class_id:1, “scores.score”:1, “score.type”:1} )

Question 10

Given the following query:db.test.find({ reports: { $elemMatch: { item: “123”, point: { $gte: 8 }}}}}Which two documents from collection test will be returned by this query? (Choose two.)

  1. { “_id” : 4, “reports” : { “item” : “123”, “point” : 8 } }
  2. { “_id” : 3, “reports” : [ { “item” : “123”, “point” : 8 },{ “item” : “213”, “point” : 7 } ] }
  3. { “_id” : 2, “reports” : [ { “item” : “123”, “point” : 6 },{ “item” : “213”, “point” : 10 } ] }
  4. { “_id” : 1, “reports” : [ { “item” : “123”, “point” : 9 },{ “item” : “213”, “point” : 7 } ] }