C100DEV

C100DEV practice questions, page 4 of 4, with answer review and explanations.

Question 16

What mongosh function displays the indexes associated with the pets collection?

  1. db.pets.getIndexes()
  2. db.pets.showAllIndexes()
  3. db.pets.indexesCollDetails()
  4. db.pets.indexDetails()

Question 17

Given the following sample documents in the inventory collection:What expression will remove only one document with “status”:“A” in the inventory collection?

  1. db.inventory.deleteMany ({“status”: “A”})
  2. db.inventory.deleteOne ({“status”: “A”})
  3. db.inventory.insertOne ({“status”: “A”})
  4. db.inventory.remove ({“status”: “A”})

Question 18

Given a people collection with the following documents:{ _id: 0, name: “Emma”, sports: [ “Soccer”, “Badminton” ] },{ _id: 1, name: “James”, sports: [ “Basketball”, “Tennis” ] },{ _id: 2, name: “Lucas”, sports: [ “Soccer”, “Basketball” ] },{ _id: 3, name: “Sophia”, sports: “Tennis” },{ _id: 4, name: “Mike”, sports: [ “Basketball”, “Soccer” ] },{ _id: 5, name: “Grace”, sports: [ “Soccer”, “Basketball”, “Badminton”, “Table Tennis” ] },What option lists all the documents that match the following query? db.people.find( {sports: “Tennis” } )

  1. { _id: 3, name: “Sophia”, sports: “Tennis” },
  2. { _id: 1, name: “James”, sports: [ “Basketball”, “Tennis” ] },{ _id: 3, name: “Sophia”, sports: “Tennis” },
  3. { _id: 1, name: “James”, sports: [ “Basketball”, “Tennis” ] },{ _id: 3, name: “Sophia”, sports: “Tennis” },{ _id: 5, name: “Grace”, sports: [ “Soccer”, “Basketball”, “Badminton”, “Table Tennis” ] },
  4. { _id: 1, name: “James”, sports: [ “Basketball”, “Tennis” ] },

Question 19

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));