【发布时间】:2015-04-21 23:30:21
【问题描述】:
我正在使用批量更新插入来一次更新/添加多个文档到我的数据库:
var bulk = collection.initializeUnorderedBulkOp();
docs.forEach(function(doc, index, array){
bulk.find({'docId' : doc.docId}).upsert().updateOne(doc);
});
bulk.execute();
在bulk.execute 这将返回以下错误:
/myPath/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:771
catch(err) { process.nextTick(function() { throw err}); }
^
TypeError: undefined is not a function
at /myPath/node_modules/mongodb/lib/bulk/unordered.js:470:5
我查看了 mongodb 模块中的代码,这里的回调似乎失败了:
// Execute batches
return executeBatches(this, function(err, result) {
callback(err, result);
});
数据正在完全按预期写入数据库,但仍然抛出此错误,我无法弄清楚我可以做些什么来导致它。
我已经排除了我的数据问题,方法是使用普通对象,并使用批量插入而不是 upsert,因为它们更简单,但结果是相同的。
【问题讨论】: