我试图上传5000多个来自CSV的评论,然后将它们插入到一个集合中。
我得到以下信息:
all done dfae22fc33f08cde515ac7452729cf4921d63ebe.js:24
insert failed: MongoError: E11000 duplicate key error index: ag5Uriwu.comments.$_id_ dup key: { : "SuvPB3frrkLs8nErv" } dfae22fc33f08cde515ac7452729cf4921d63ebe.js:1
Connection timeout. No DDP heartbeat received. 手边的剧本:
'click .importComments': function(e) {
var $self = $(e.target);
$self.text("Importing...");
$("#commentsCSV").parse({
worker: true,
config: {
step: function(row) {
var data = row.data;
for (var key in data) {
var obj = data[key];
post = Posts.findOne({legacyId: obj[1]});
var comment = {
// attributes here
};
Comments.insert(comment);
Posts.update(comment.postId, {
$inc: { commentsCount: 1 },
});
}
$self.text("Import Comments");
},
complete: function(results, file) {
console.log("all done");
}
}
});
}如何才能在不发生连接超时错误的情况下工作呢?
在当地,它似乎工作得很体面,但在生产(modulus.io)上却突然结束了。
发布于 2014-08-08 07:34:24
我认为这里的问题不是与DDP有关,而是与MongoDB有关。由于MongoDB错误,DDP连接正在超时。
您将在_id字段上得到一个重复的键错误。_id字段由MongoDB自动索引,它是唯一的索引,因此相同的值不能在同一个集合中出现两次。
您正在上传的CSV可能有它自己的_id字段,这意味着Mongo没有生成它自己的二进制字段(这保证了唯一性)。
因此,如果存在_id字段,我建议将其从CSV中删除。
您还可以尝试使用以下包:http://atmospherejs.com/package/csv-to-collection
https://stackoverflow.com/questions/25181092
复制相似问题