nerdexam
MongoDB

C100DBA · Question #114

Dada una coleccion, cuales devuelve con la siguiente query db.coleccion.find({nombre:"ruben",apellido:"gomez"},{nombre:l,apellido:l,aficion:l});

Option D is correct because the query applies two conditions simultaneously in the filter document - nombre:"ruben" AND apellido:"gomez" - so only documents matching both fields are returned. The projection {nombre:1, apellido:1, aficion:1} then specifies which fields to…

MongoDB Fundamentals

Question

Dada una coleccion, cuales devuelve con la siguiente query db.coleccion.find({nombre:"ruben",apellido:"gomez"},{nombre:l,apellido:l,aficion:l});

Options

  • A{ "-id" : Objectld("580a42b5dfblb5al7427d302"), "nombre" : "ruben", "apellido" : "gomez",
  • B{ "_id" : Objectld("580a42acdfblb5al7427d301"), "nombre" : "Luis", "apellido" : "gomez", "aficion"
  • C{ "_id" : Objectld("580a42acdfblb5al7427d301"), "nombre" : "ruben", "apellido" : "Pablo" ,
  • D{ "_id" : Objectld("580a42acdfblb5al7427d301"), "nombre" : "ruben", "apellido" : "gomez" >

Explanation

Option D is correct because the query applies two conditions simultaneously in the filter document - nombre:"ruben" AND apellido:"gomez" - so only documents matching both fields are returned. The projection {nombre:1, apellido:1, aficion:1} then specifies which fields to include in the output, and MongoDB always includes _id by default unless explicitly excluded with _id:0.

Option B is wrong because its nombre is "Luis", which fails the nombre:"ruben" filter condition - it would never be returned.

Option C is wrong because its apellido is "Pablo", which fails the apellido:"gomez" filter condition.

Option A is a distractor that may appear similar to D but contains a malformed "-id" field and is inconsistent with how MongoDB returns a valid matching document with the given projection.

Memory tip: Think of the find() filter as a checklist - all key-value pairs must match (implicit AND). If even one field doesn't match, the document is excluded. The second argument (projection) only controls what you see, not what you find.

Topics

#find query#projection#query filter#field selection

Community Discussion

No community discussion yet for this question.

Full C100DBA Practice