Mongoid 删除许多限制 [英] Mongoid delete many with limit

查看:47
本文介绍了Mongoid 删除许多限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用mongoid,如何删除error_message字段为:Error: not found的前10000个文档.

Using mongoid, how to delete the first 10000 documents where the error_message field is: Error: not found.

本机 mongo 查询将被愉快地接受

Native mongo queries will be happily accepted

推荐答案

MongoDB 支持删除限制.

MongoDB support limit on delete.

删除命令从集合中删除文档.一个删除命令可以包含多个删除规范

The delete command removes documents from a collection. A single delete command can contain multiple delete specifications

{
   delete: <collection>,
   deletes: [
      { q : <query>, limit : <integer>, collation: <document> },
      { q : <query>, limit : <integer>, collation: <document> },
      { q : <query>, limit : <integer>, collation: <document> },
      ...
   ],
   ordered: <boolean>,
   writeConcern: { <write concern> }
}

https://docs.mongodb.com/manual/参考/命令/删除/#dbcmd.delete

其中q"是您对特定输入数据的查询(必须与您要删除的文档匹配),limit"是要删除的最大文档数.如您所见,可能有多个删除条件,但超出了您的问题范围.

where 'q' is your query with your specific input data (that must match the documents you want to delete) and 'limit' is the number of max documents to delete. As you can see, there is the possibility to have multiple delete conditions but is out of the scope of your question.

这篇关于Mongoid 删除许多限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆