MongoDB:使用“$in”更新多个
在 mongodb 集合中执行“更新”时需要一些关于使用“$in”的专家建议。 这是一个例子:
db.users.update({userid: {$in: ['1','2','3']}}, {$inc: {mycounter: 1}}, false, true);
在这种情况下使用“$in”是否更好?如果在我的上述场景中“$in”的数组计数/大小有任何限制,那么任何人都可以指导我,每次更新可能有 10k+ 用户 ID。
谢谢。
Need some expert suggestions on using '$in' while performing 'update' in mongodb collections.
Here is an example:
db.users.update({userid: {$in: ['1','2','3']}}, {$inc: {mycounter: 1}}, false, true);
is it better to use '$in' in this scenario? Also can anyone guide me if there is any limit for array count/size for '$in' in my above scenario it might be 10k+ user ids per update..
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从 shell 进行了以下简单测试:
性能还算合理,看起来可以处理 10k 同时更新。
我找不到任何迹象表明数组大小存在硬限制。我认为你可以在这里应用一个“合理”的限制。即使您可以发出包含 100k 数组的命令,这也将很难跟踪。
某些驱动程序还允许批量更新命令,这可能更适合您正在执行的操作。
Ran the following simple test from the shell:
Performance was reasonable, seems like it can handle 10k simultaneous updates.
I can't find any indication that there's a hard limit on the array size. I think you can apply a "reasonable" limit here though. Even if you can issue commands of with an array of 100k, that's going to be difficult to track.
Some drivers also allow for bulk update commands, which may be more appropriate for what you're doing.