如何限制mongodb中更新文档的数量 [英] How to limit number of updating documents in mongodb

查看:171
本文介绍了如何限制mongodb中更新文档的数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在更新文档时如何实现类似于db.collection.find().limit(10)的功能?

How to implement somethings similar to db.collection.find().limit(10) but while updating documents?

现在我正在使用一些非常糟糕的东西,例如使用db.collection.find().limit()获取文档然后进行更新.

Now I'm using something really crappy like getting documents with db.collection.find().limit() and then updating them.

通常,我想返回给定数量的记录,并在每个记录中更改一个字段.

In general I wanna to return given number of records and change one field in each of them.

谢谢.

推荐答案

不幸的是,您拥有的解决方法是执行AFAIK的唯一方法.有一个布尔标志multi,它将更新所有匹配项(true时)或更新第一个匹配项(false时).

Unfortunately the workaround you have is the only way to do it AFAIK. There is a boolean flag multi which will either update all the matches (when true) or update the 1st match (when false).

这篇关于如何限制mongodb中更新文档的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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