2015-04-21 17 views
2

我使用的是散裝UPSERT更新/一次到我的數據庫添加多個文件「undefined是不是一個函數」使用無序散時UPSERT

/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); 
}); 

數據正在按照預期寫入數據庫,但是這個錯誤仍然在被拋出,我無法弄清楚我能做些什麼來實現它。

我以瑣碎的對象,並通過批量插入代替upserts,因爲它們是簡單的排除了與我的數據的問題,但結果是一樣的。

回答

3

您需要invoke bulk.execute with a callback

bulk.execute(function(err,results) { 
    if(err) 
     console.error(err); 
    else 
     console.log(results); 
}); 

或類似的,應該工作。

+0

謝謝,從字面上來看,只是想通了,它沒有在我看到的文檔中提到。 – Carasel