我正在使用 MongoDb 和 Nodejs。Nodejs 托管在 Heroku 服务器上,而 Mongodb 通过 Heroku 插件在 MongoLab 中。
安装 MongoLab 插件后,我收到了这个 URI:
mongodb://<dbuser>:<dbpassword>@ds053148.mongolab.com:53148/heroku_app18934798
我不知道如何使用这个URI,请帮忙?放在哪里?什么是<dbuser>:<dbpassword
这是我在 mongoDB 中关心的配置locallhost
在server.js
var env = process.env.NODE_ENV || 'development',
config = require('./config/config')[env],
mongoose = require('mongoose');
var db = mongoose.connect(config.db);
在express.js
app.use(express.session({
secret: 'thissecret',
key:'express.sid',
store: new mongoStore({
url: config.db,
collection: 'sessions'
})
}));
在config.js
module.exports = {
development: {
db: 'mongodb://localhost/mean-dev',
root: rootPath,
app: {
name: 'MEAN - A Modern Stack - Development'
},
facebook: {
clientID: "APP_ID",
clientSecret: "APP_SECRET",
callbackURL: "http://localhost:3000/auth/facebook/callback"
}
},
test: {
db: 'mongodb://localhost/mean-test',
root: rootPath,
app: {
name: 'MEAN - A Modern Stack - Test'
},
facebook: {
clientID: "APP_ID",
clientSecret: "APP_SECRET",
callbackURL: "http://localhost:3000/auth/facebook/callback"
}
},
production: {
db: 'mongodb://localhost/mean',
root: rootPath,
app: {
name: 'MEAN - A Modern Stack - Production'
},
facebook: {
clientID: "APP_ID",
clientSecret: "APP_SECRET",
callbackURL: "http://localhost:3000/auth/facebook/callback"
}
}
};