1.

Which of the following query selects documents in the records collection that match the condition { “user_id”: { $lt: 42 } }?(a) db.records.findOne( { “user_id”: { $lt: 42 } }, { “history”: 0 } )(b) db.records.find( { “user_id”: { $lt: 42 } }, { “history”: 0 } )(c) db.records.findOne( { “user_id”: { $lt: 42 } }, { “history”: 1 } )(d) db.records.select( { “user_id”: { $lt: 42 } }, { “history”: 0 } )The question was posed to me during an online interview.The origin of the question is Read Operations in division MongoDB CRUD Concepts and Operation of MongoDB

Answer»

Right answer is (B) db.records.find( { “user_id”: { $lt: 42 } }, { “history”: 0 } )

To elaborate: Query uses the projection { “history”: 0 } to EXCLUDE the history field from the documents in the result SET.



Discussion

No Comment Found

Related InterviewSolutions