MongoDB DEV · 题目 186 · 单选

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:

题目选项

  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" ) } )

答案置信度:高

正确答案:C

解析语言:中文

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

所在套题

此题在题库中有 3 条记录。公开详情合并相同题干和选项;完整公开题展示置信度最高的一条记录,其他题目仅展示摘要。按套学习保留每条记录原有的答案、解析和置信度。

作者 · 作品 · 开源

作者与 MongoDB 作品

专注数据平台、MongoDB 迁移同步与云运维产品研发。

有任何 MongoDB 需求,均可联系作者。

联系作者 ↗mlhp123@outlook.com

支持作者

如果题库对您有帮助,欢迎自愿扫码打赏。

支付宝扫码打赏作者打开打赏原图 ↗