title: How to connect mongodb(mongoose) with username and password?
body: <p>I have username and password for mongoose, i used this url to connect the mongodb using mongoose </p>
  
  <p>I try this one :</p>
  
  <pre><code>var mongoose = require('mongoose');
  mongoose.Promise = global.Promise;
  mongoose.connect('mongodb://adminuser:123456@localhost:2017/mydb');
  </code></pre>
  
  <p>mongoose schema is </p>
  
  <pre><code>  // grab the things we need
    var mongoose = require('mongoose');
    var Schema = mongoose.Schema;
  
    // create a schema
    var userSchema = new Schema({
    name: String,
    username: { type: String, required: true, unique: true },
    password: { type: String, required: true },
    admin: Boolean,
    location: String,
    meta: {
    age: Number,
    website: String
    },
    created_at: Date,
    updated_at: Date
    });
  
    // the schema is useless so far
    // we need to create a model using it
    var User = mongoose.model('User', userSchema);
  
    // make this available to our users in our Node applications
    module.exports = User;
  </code></pre>
  
  <p>and my controller is </p>
  
  <pre><code>    router.post('/signup',function(req,res){
       console.log("Inside")
       var useR= new User({
        name: 'Chris',
        username: 'sevilayha',
        password: 'password' 
       });
       useR.save(function(err) {
        if (err) throw err;
        console.log('User saved successfully!');
       });
      });
  </code></pre>
  
  <p>but its not stored in database .</p>