0
我有一個基於koa的應用程序,我想將數據寫入nedb。 這個問題在下面的短片段中顯示。從nedb回調中產生
app.use(router.get('/', function*(){
db.insert(doc, function(err,data){
// can't yield here because the callback is not a generator
}
}));
我試圖在https://github.com/tj/node-thunkify與thunkify按文件執行以下操作:
var insert = thunkify(db.insert);
app.use(router.get('/', function*(){
yield insert(doc)
}))
,但我得到以下錯誤
TypeError: Cannot read property 'push' of undefined
at Datastore.insert (/home/app/node_modules/nedb/lib/datastore.js:374:16)
at Object.<anonymous> (/home/app/node_modules/thunkify/index.js:43:12)
at /home/app/node_modules/koa/node_modules/co/index.js:136:8
at Object.thunkToPromise (/home/app/node_modules/koa/node_modules/co/index.js:13
任何幫助將不勝感激。