我可以使用正则表达式删除mongodb的文档吗?

Can*_*noe 8 mongodb mongodb-query

我还没有找到一种方法来做到这一点.如果我们无法使用正则表达式删除文档,我们可以做些什么来完成它?为什么mongodb不提供这样的驱动程序?

Nei*_*unn 11

.remove()方法只接受一个查询对象,因此正则表达式只是MongoDB的标准查询:

db.collection.remove({ "field": /^string/ })
Run Code Online (Sandbox Code Playgroud)

删除任何以"string"开头的"field"

请查看文档$regex.