title: How collection referencing works in mongoose?
body: <p>First time i am trying to use refrence in mongoose , so i am trying to understand if i want to save template with user id , Do we need to get <code>createdBy</code> value from client or how it will be inserted into <code>templateSchema</code>. basically i want to save user id <code>_id</code> when user save template.I was able to save template but i did not get any error and <code>createdBy</code> property did not saved to template collection. Any layman explanation to understand refrencing in mongoose and how i can make it work with below code. </p>
  
  <p>user.js</p>
  
  <pre><code>var UserSchema = new mongoose.Schema({
    _id: { type: String, required: true, index: {unique: true}},
    firstName: String,
    lastName: String,
    type: String,
    groups:[{type: String, ref: 'Group', required: false}]
  },
    {
      toObject: {
        virtuals: true
      },
      toJSON: {
        virtuals: true
      }
    });
  </code></pre>
  
  <p>template.js</p>
  
  <pre><code>var User = require('../user/user.model.js');
  
  var TemplateSchema = new mongoose.Schema({
    _id: { type: String, required: true},
    name: String,
    id: String,
    appliesTo: [],
    properties: [],
    createdBy: { type: mongoose.Schema.Types.ObjectId, ref: 'User'}
   });
  </code></pre>
  
  <p>templateCtrl.js</p>
  
  <pre><code>var eTemplate = require('./template.model');
  
  var templatesJavaClass = {
            "_id": 12586,
            "name": "Java Class",
            "id": "javaClass",
            "appliesTo": [
                "bpmn:UserTask"
            ],
            "properties": [{
                "label": "Java Package Name",
                "type": "String",
                "editable": true,
                "binding": {
                    "type": "property",
                    "name": "camunda:class"
                }
            }],
          "createdBy": "user1"
        }
  
   var template = new eTemplate(templatesJavaClass);
  
   template.save(function(error){
    console.log("successfully saved template");
    if (error){
      console.log(error);
    }
   });
  </code></pre>