I am using MongoDb and Nodejs. Nodejs is hosted on Heroku server and Mongodb is in MongoLab through Heroku add-on.
After installed MongoLab add-on, I received this URI:
mongodb://<dbuser>:<dbpassword>@ds053148.mongolab.com:53148/heroku_app18934798
I do not know how to use this URI, please help?
Where to put it? what is <dbuser>:<dbpassword
This is my config which is concern to mongoDB in locallhost
In server.js
var env = process.env.NODE_ENV || 'development',
config = require('./config/config')[env],
mongoose = require('mongoose');
var db = mongoose.connect(config.db);
In express.js
app.use(express.session({
secret: 'thissecret',
key:'express.sid',
store: new mongoStore({
url: config.db,
collection: 'sessions'
})
}));
In 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"
}
}
};
You can connect to the database using the following:
var mongoose = require('mongoose');
mongoose.connect('mongodb://<dbuser>:<dbpassword>@ds053148.mongolab.com:53148/<database name>');
But in your case I would replace mongodb://localhost/<database name>
with mongodb://<dbuser>:<dbpassword>@ds053148.mongolab.com:53148/<database name>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With