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?
db.pets.getIndexes()
db.pets.showAllIndexes()
db.pets.indexesCollDetails()
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?
db.inventory.deleteMany ({“status”: “A”})
db.inventory.deleteOne ({“status”: “A”})
db.inventory.insertOne ({“status”: “A”})
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” } )
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?
collection.DeleteOne(eq(“_id”, new ObjectID(3))));