【发布时间】:2016-02-20 21:27:08
【问题描述】:
我正在尝试将数千条记录导入 Meteor 集合中的嵌套数组中。这是来自 JSON 对象的财务数据。我需要在插入它之前对其进行一些计算,所以不能这样做。为每次写入执行 $addToSet 操作非常非常慢。有没有办法在一次调用中推送完整的数据集?
我的架构看起来像这样。
NestedSchema = new SimpleSchema({
item: {
type: String
},
aThing: {
type: Number
}
});
MasterSchema = new SimpleSchema({
symbol: {
type: String,
label: 'Symbol',
unique: true
},
data: {
type: [NestedSchema],
optional: true
}
});
我有一堆这样的数据要插入。
var dataToInsert = [{item: "thing", aThing: 1}, {item: "thing2", aThing: 2}, {item: "thing3", aThing: 2}];
我试图插入嵌套数组的数据是 5000 多条记录。我看过https://atmospherejs.com/udondan/bulk-collection-update 和https://atmospherejs.com/mikowals/batch-insert,但它们似乎并没有完全符合我的要求。理想情况下,我有一个解决方案,可以在收集新记录时批量追加它们。
【问题讨论】:
-
您是否使用
$addToSet来避免上当受骗?如果没有骗子,那么只需$push,那应该会快很多。或者你可以在内存中创建整个数组然后一次性插入吗?
标签: javascript arrays mongodb meteor