我正在尝试连接到我的mongodb数据库,但它不起作用:它没有运行回调,也没有抛出错误:
var config = require('./config');
var mongoose = require('mongoose');
var schemas = require('./app/schemas');
var model = require('./app/model');
mongoose.connect(config.db_connection, function (err) {
if (err) {
throw err;
}
});
var ModModel = mongoose.model('mods', schemas.modScheme);
var query = ModModel.find();
query.exec('find', function (err, mods) {
if (err) {
throw err;
}
console.log('Retriveing mods...');
console.log(mods);
});
编辑:这个新代码不起作用
以下是整个代码:https://github.com/CraftYourModCorporation/RedstoneHub (可能不完整,路由getmods)
有人可以链接使用mongoose的项目吗?
输出:
Important: use 'process.env.PORT' as the port and 'process.env.IP' as the host in your scripts!
debugger listening on port 15400
Process terminated
答案 0 :(得分:1)
谢谢大家,问题是连接字符串:而不是使用mongodb:// user:pass @ host / db连接,我不得不使用选项。更多详情:http://mongoosejs.com/docs/connections.html