node.js - Can't find Db in mongodb while using mongoose -


the following code, works fine giving output enter image description here.

var mongoose=require('mongoose'); var dburl='mongodb://localhost:27017/trial1';  mongoose.connect(dburl);  //creating schema     var userschema=new mongoose.schema({         name:string,         email:string,         createdon:date     });   mongoose.model('user',userschema); var user=mongoose.model('user');  var userone=new user({name:'mike'}); console.log(userone.name);   mongoose.connection.on('connected',function(){ console.log('mongoose connected '+dburl); });  mongoose.connection.close(function(){     console.log('connection closed!!!!'); }); 

but when try search db in connection string (ie)trial1, not able find it, screen shot follows. enter image description here

also when "use trial1" in mongo shell i'm getting output per following screen shot.enter image description here means db exists or been created. why not able see db??

so yes answer in comment of blakes , part of answer pio.

you don't see databases because mongoose code not create user in it. when instantiate model user create in memory not in database. insert user in database must call method save on instance this:

var userone=new user({name:'mike'}); userone.save(function(err, user){   if (!err) {     console.log('now user saved in database');   } }) 

so if don't save user, in mongo shell won't see databases empty , not exists.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -