猫鼬插入很多限制 [英] Mongoose insertMany limit
问题描述
猫鼬4.4现在具有insertMany
函数,该函数可让您验证一组文档,如果有效,则通过一个操作(而不是每个文档一个)插入它们:
Mongoose 4.4 now has an insertMany
function which lets you validate an array of documents and insert them if valid all with one operation, rather than one for each document:
var arr = [{ name: 'Star Wars' }, { name: 'The Empire Strikes Back' }];
Movies.insertMany(arr, function(error, docs) {});
var arr = [{ name: 'Star Wars' }, { name: 'The Empire Strikes Back' }];
Movies.insertMany(arr, function(error, docs) {});
如果阵列非常大,应该批量处理吗?还是对大小或数组没有限制?
If I have a very large array, should I batch these? Or is there no limit on the size or array?
例如,我想为每个电影创建一个新文档,而我有10,000部电影.
For example, I want to create a new document for every Movie, and I have 10,000 movies.
推荐答案
我建议根据个人经验,批量为100-200时,可以很好地融合性能,而又不会给系统造成压力.
I'd recommend based on personal experience, batch of 100-200 gives you good blend of performance without putting strain on your system.
insert许多操作组最多可以有1000个操作.如果组超过此限制,则MongoDB会将组划分为1000个或更少的较小组.例如,如果队列包含2000个操作,则MongoDB将创建2个组,每个组包含1000个操作.
insertMany group of operations can have at most 1000 operations. If a group exceeds this limit, MongoDB will divide the group into smaller groups of 1000 or less. For example, if the queue consists of 2000 operations, MongoDB creates 2 groups, each with 1000 operations.
大小和分组机制是内部性能的详细信息,在将来的版本中可能会发生更改.
The sizes and grouping mechanics are internal performance details and are subject to change in future versions.
在分片集合上执行操作的有序列表通常比执行无序列表要慢,因为有了有序列表,每个操作都必须等待上一个操作完成.
Executing an ordered list of operations on a sharded collection will generally be slower than executing an unordered list since with an ordered list, each operation must wait for the previous operation to finish.
这篇关于猫鼬插入很多限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!