【发布时间】:2015-11-05 12:24:35
【问题描述】:
我想insert an array 将数千个对象放入一个 MongoDB 集合中。
db.col.insert(
[
{ },
{ },
{ } // A couple of 1000s more
],
{
ordered : false,
writeConcern : 0
}
);
但是,我还想使用元数据来识别这些组。数组中的每条记录都需要分配一些数据,并且该数据对于数组中的所有记录都是相同的。
有没有一种方法可以插入所有文档,并为所有文档设置例如:
{
dateTime : '111111111',
groupId : 'some hash',
batchId : 'other hash'
}
没有手动将其手动添加到数组中的数千条记录中?那将是一个很大的性能下降(而且很丑)。
我曾经将这些记录与元数据一起添加为一个数组:
{
dateTime : '111111111',
groupId : 'some hash',
batchId : 'other hash',
batchArr : [ array with thousands of records]
}
并在上面使用$unwind。但是,这不再可能,因为记录数开始超过 MongoDB 的16 MB BSON size limit。
【问题讨论】:
标签: arrays performance mongodb