我正在尝试使用以下方法访问monk中find方法返回的数据:
var collection = db.get('Workflow');
collection.find({},{},function(e,workflow){
console.log(workflow);
var req0 = workflow[0]; //Error here
console.log(req0);
console.log(req0, req.body.accountType);
});
第一个console.log(工作流)正确地返回整个记录,看起来像一个json数组。但是,当我尝试访问时,它会给我以下错误:
TypeError: Cannot read property '0' of undefined
at Promise.<anonymous> (C:\Users\abchauhan\Desktop\Work\NodeLearning\HelloNode\routes\index.js:68:38)
at Promise.<anonymous> (C:\Users\abchauhan\Desktop\Work\NodeLearning\HelloNode\node_modules\monk\node_modules\mpromise\lib\promise.js:178:8)
at Promise.emit (events.js:117:20)
at Promise.emit (C:\Users\abchauhan\Desktop\Work\NodeLearning\HelloNode\node_modules\monk\node_modules\mpromise\lib\promise.js:84:38)
at Promise.fulfill (C:\Users\abchauhan\Desktop\Work\NodeLearning\HelloNode\node_modules\monk\node_modules\mpromise\lib\promise.js:97:20)
at Promise.resolve (C:\Users\abchauhan\Desktop\Work\NodeLearning\HelloNode\node_modules\monk\node_modules\mpromise\lib\promise.js:126:15)
at C:\Users\abchauhan\Desktop\Work\NodeLearning\HelloNode\node_modules\monk\node_modules\mongoskin\node_modules\mongodb\lib\mongodb\cursor.js:163:16
at commandHandler (C:\Users\abchauhan\Desktop\Work\NodeLearning\HelloNode\node_modules\monk\node_modules\mongoskin\node_modules\mongodb\lib\mongodb\cursor.js:709:16)
at C:\Users\abchauhan\Desktop\Work\NodeLearning\HelloNode\node_modules\monk\node_modules\mongoskin\node_modules\mongodb\lib\mongodb\db.js:1846:9
at Server.Base._callHandler (C:\Users\abchauhan\Desktop\Work\NodeLearning\HelloNode\node_modules\monk\node_modules\mongoskin\node_modules\mongodb\lib\mongodb\connection\base.js:445:41)
答案 0 :(得分:0)
因为它不返回数组。如果您只需要第一条记录,为什么不尝试'限制'
ALTER TABLE Users ADD NormalizedName AS UPPER(UserName);
CREATE NONCLUSTERED INDEX [IX_NormalizedName] ON [Users] ([NormalizedName] ASC);