MongoDB DEV · Question 186 · Single choice

Your organization has decided to remove all emails from the last century stored in the emails collection. The timestamp for emails in your collection is stored in a field called date. Which of the following queries will achieve this result? Choose the best answer:

Answer options

  1. A.
    db.emails.delete( { "date": { "$lt": new Date( "2000-01-01" ) } } )
  2. B.
    db.emails.deleteOne( { "date": { "$before": new Date( "2000-01-01" ) } } )
  3. C.
    db.emails.deleteMany( { "date": { "$lt": new Date( "2000-01-01" ) } } )
  4. D.
    db.emails.drop( { "date": { "$lt": new Date( "2000-01-01" ) } } )
  5. E.
    db.emails.deleteMany( { "date": new Date( "2000-01-01" ) } )

Answer confidence: High

Correct answer: C

Explanation language: Chinese

要删除多条文档必须用 deleteMany,时间条件用 $lt new Date("2000-01-01") 表示 2000 年之前的"上个世纪"邮件,故 B 正确。A 的 $before 不是 MongoDB 操作符;C 是日期等值匹配;D 的 db.emails.delete() 不是集合的有效方法;E 的 drop 会删除整个集合且不接受查询条件。

Papers containing this question

This question appears in 3 bank records. Public pages combine identical prompts and options. Selected questions display the highest-confidence record; the others show a short preview. Paper-based learning preserves each record's answer, explanation, and confidence.

AUTHOR · PROJECTS · OPEN SOURCE

Author & MongoDB projects

Building data platforms, MongoDB migration and sync tools, and cloud operations products.

Contact the author for any MongoDB needs.

Contact the author ↗mlhp123@outlook.com

Support the author

If this question bank helps you, optional donations are welcome.

Scan with Alipay to support the authorOpen full-size donation image ↗