【发布时间】:2018-06-21 17:58:11
【问题描述】:
我试图从 mongoose 查询中获取数据,该查询在另一个 js 文件中返回
我的代码:
config.js
module.exports = {
FindinCol1: function() {
console.log("Inside promise")
mongo.configuration.findOne({}).exec()
.then(function(user){
// var result = [];
console.log("user");
resolve(user);
})
.then(undefined, function(err){
console.log(err)
})
}
};
route.js
更新
var siteconfig = require('./config');
siteconfig.FindinCol1().then(function(items) {
console.info('The promise was fulfilled with items!', items);
}, function(err) {
console.error('The promise was rejected', err, err.stack);
});
我不知道自己犯了什么错误。
【问题讨论】:
-
你得到的错误是什么?
-
无法读取未定义的 then 的属性
-
是否打印了任何控制台语句?
-
siteconfig.FindinCol1(function(items) { console.log(items); });我已经尝试过了,现在我没有收到错误,但是值在 config.js 中打印,但在 route.js 中没有
-
在“mongo.configuration.findOne”之前添加一个返回
标签: node.js mongodb mongoose promise