【发布时间】:2012-10-23 05:44:15
【问题描述】:
在尝试 node.js 框架 geddy(在 Windows 上)时,我遇到了一些问题。
我正在尝试在我的控制器中使用用户模型中的 .first() 方法查询 mongodb,如下所示:
geddy.model.User.first({name: 'jdoe'}, function (err, data) {
if (err) {
throw err;
} else {
console.log(data);
}
});
奇怪的是,我没有得到任何输出、错误,什么也没有。用户 jdoe 存在于集合中,所以它应该输出一些东西,对吗?我做错了吗?
我的模型定义为:
var User = function () {
this.defineProperties({
username: {type: 'string', required: true},
password: {type: 'string', required: true},
});
this.autoIncrementId = true;
};
User = geddy.model.register('User', User);
默认适配器在 development.js 中设置为 mongo,当我第一次运行 geddy 时,它创建了我的数据库并正确插入了用户集合。
你知道这里出了什么问题吗?
更新:
根据要求添加了 development.js
var config = {
detailedErrors: true
, debug: true
, hostname: null
, port: 4000
, model: {
defaultAdapter: 'mongo',
}
,db: {
mongo: {
dbname: 'knowledgebase'
}
}
, sessions: {
store: 'memory'
, key: 'sid'
, expiry: 14 * 24 * 60 * 60
}
};
module.exports = config;
还有我在 mongo 上的收藏(由 geddy 创建)
> show collections
User
system.indexes
users
请注意,geddy 以某种方式创建了两个集合而不是一个
【问题讨论】:
-
我可以看看你的配置文件吗?没有它,我将无法说出这里发生了什么:)
-
另外,你能告诉我你的数据库中的集合列表吗?
-
使用 config 和 mongo 集合编辑了我的帖子。昨天 .all()/.first() 命令不会成功查询 mongo,今天他们可以。奇怪!是否与正在创建的“重复”集合有关?