title: How to add reference of one schema to another in Mongoose and inserting data by json?
body: <p>I am writing a node.js app where I have two mongoose schemas <em>Wallet</em> and <em>User</em>. </p>
  
  <ul>
  <li>I want to add <strong><em>Wallet as a reference to User</em></strong> and pass the appropiate json from POSTMAN. This is like adding a reference of one class in another in OOPs and foreign key concept in RDBMS.</li>
  </ul>
  
  <p>I have written the schemas like this:</p>
  
  <p><strong>user.js</strong></p>
  
  <pre><code>var mongoose = require('mongoose');
  
  var userSchema = new mongoose.Schema({
      userId: {type: String},
      isAdmin: {type: Boolean, default: false},
      password: {type: String},
      name: {type: String},
      wallet: {type: mongoose.Schema.Types.ObjectId, ref: 'Wallet'} //see here
  });
  
  module.exports = mongoose.model('User', userSchema);
  </code></pre>
  
  <p>Is the way I referenced wallet above, correct? If not, can you tell me the right way?</p>
  
  <p><strong>wallet.js</strong></p>
  
  <pre><code>var mongoose = require('mongoose');
  
  var walletSchema = new mongoose.Schema({
      money: {type: Number, default: 0, min: 0},  
  });
  
  module.exports = mongoose.model('Wallet', walletSchema);
  </code></pre>
  
  <p>The following is my user route file.</p>
  
  <p><strong>userRoute.js</strong></p>
  
  <pre><code>router.route('/user')
  
  .post(function (req, res) {
  
      var user = new User();
  
      user.userId = req.body.userId;
      user.password = req.body.password;
      user.name = req.body.name;
      user.isAdmin = req.body.isAdmin;
      user.wallet = req.body.wallet; // see here
  
      user.save(function(err, user){
          if(err){
              res.json({ message: 'Failure' });
              return false;           
          }
          res.json({ message: 'Success' });
      });     
  })
  </code></pre>
  
  <p>Is the way I have assigned wallet to the user object correct? If not can you tell me the right way?</p>
  
  <p>Now I want to post raw json from Postman. What will the json look like?</p>