Mongoid delete many with limit

╄→гoц情女王★ 提交于 2021-01-28 10:42:12

问题


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

Native mongo queries will be happily accepted


回答1:


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/reference/command/delete/#dbcmd.delete

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.



来源:https://stackoverflow.com/questions/51917027/mongoid-delete-many-with-limit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!