連接到本地的MongoDB服務器這不能試圖連接到從項目目錄我得到MONGO分貝時的NodeJS
/用戶/ tadeothompson /文檔/設計工作/壓力/網站/ node_modules /連接 - 蒙戈/ lib/connect-mongo.js:133 throw err; ^ MongoError:無法連接到服務器 在Collection.listIndexes(/ Users/tadeothompson/Documents/design work/stressful/site/node_modules/mongoose/node_modules/mongodb/lib/collection.js:1712:11) at indexInformation (/ Users/tadeothompson/Documents/designwork/stressful/site/node_modules/mongoose/node_modules/mongodb/lib/db.js:1531:25) at Db.indexInformation(/ Users/tadeothompson/Documents/design work/stressful /site/node_modules/mongoose/node_modules/mongodb/lib/db.js:1498:44) at ensureIndex(/ Users/tadeothompson/Documents/design work/stressful/site/node_modules/mongoose/node_modules/mongodb/lib/db .js:1003:8) at Db.ensureIndex(/ Users/tadeothompson/Documents/design work/stressful/site/node_modules/mongoose/node_modules/mongodb/lib/db.js:982:44) at ensureIndex(/ Users/tadeothompson/Documents/design work/stressful/site/node_modules/mongoose/node_modules/mongodb/lib/collection.js:1772:13) at Collection.ensureIndex(/ Users/tadeothompson/Documents/design工作/壓力/網站/ node_modules/mongoose/node_modules/mongodb/lib/collection.js:1760:44) at connectionReady(/ Users/tadeothompson/Documents/design work/stressful/site/node_modules/connect-mongo/lib/Db.collection(/ Users/tadeothompson/Documents/design work/stressful/site/node_modules/mongoose/node_modules/mongodb/lib/db.js:425:20) at initWithNativeDb(/ Users/tadeothompson/Documents/design work/stressful/site/node_modules/connect-mongo/lib/connect-mongo.js:207:20) at process._tickCallback(node.js:355:11) at Function.Module.runMain(module.js :503:11) 在啓動時(node.js中:129:16) 在node.js中:814:3
管理使用簡單的應用程序(下面的代碼)
*
var MongoClient = require('mongodb').MongoClient;
// Connect to the db
MongoClient.connect("mongodb://localhost:27017/exampleDb", function(err, db) {
if(!err) {
console.log("We are connected");
}
});
連接*
the main node file of the app in question code is below:
var express = require('express');
var bodyParser = require('body-parser');
var cookieParser = require('cookie-parser');
var expressSession = require('express-session');
var mongoStore = require('connect-mongo')({session: expressSession});
var mongoose = require('mongoose');
require('./models/users_model.js');
var conn = mongoose.connect('mongodb://localhost:27017/stressfullproject');
var app = express();
app.engine('html', require('ejs')._express);
app.set('views', './site' + '/views');
app.set('view engine', 'html');
app.use(bodyParser());
app.use(cookieParser());
app.use(expressSession({
secret: 'stress',
cookie: {maxAge: 60*60*1000},
store: new mongoStore({
db: mongoose.connection.db,
collection: 'sessions'
})
}));
require('./routes/routes')(app);
app.listen(80);
*
我定義的架構
*var mongoose = require('mongoose'),
Schema = mongoose.Schema;
var UserSchema = new Schema({
username: { type: String, unique: true },
email: String,
hashed_password: String
})
mongoose.model('User', UserSchema)*
因爲我可以與其他應用程序連接,即時通訊考慮與我的模塊之一的問題? ive遍尋。
在此先感謝
請問您能給出完整的堆棧跟蹤。 –