Kanya Ravi Kanya Ravi - 4 months ago 35
Node.js Question

Mongodb not creating database

I cant create my database 'sms-dev' in mongodb after starting the server but in my console it was printing connected to mongo successfully.I kept my db module inside models folder as db.js and export that module in another file(config.js) inside models folder

Here is the code in db.js file

var db = {
// Connects to mongoDB
connect: function(url, options) {
mongoose.connect(url, options);
mongoose.connection.on('open', function(){
console.log("Connected to mongo successfully");

mongoose.connection.on('disconnect', function(){
console.log("Mongo disconnected");

mongoose.connection.on('error',function (err) {
console.log('Mongoose default connection error: ' + err);

process.on('SIGINT', function() {
mongoose.connection.close(function () {
console.log('Mongoose default connection disconnected through app termination');


module.exports = db;

and my config.js file is

exports.database = {
url: 'mongodb://',
options: {
db: { native_parser: true,safe:true },
server: { poolSize: 10 }

I connected this db in server.js as

var dbcon = process.env.MONGOLAB_URI || config.database.url;
db.connect(dbcon, config.database.options);


It seems that my mongodb was not locked properly so i remove the mongodb.lock file and run with -repair option