title: How to assign a user a post with Mongoose and Express
body: <p>I am currently stuck on how I could assign a user a post when they create when in the website. So basically I want to have a logged in user create a resume and then have that resume assigned to that logged in user as a created_by in the schema. I kind of got it sorted but I don't know to create the resume and assign the logged in user to it.</p>
  
  <pre><code>const mongoose = require('mongoose');
  const Schema = mongoose.Schema;
  const ObjectId = Schema.ObjectId;
  var moment = require('moment');
  var id = require('../helpers/generator');
  let beautifyUnique = require('mongoose-beautiful-unique-validation');
  
  
  const ResumeSchema = new Schema({
    _id: {
      type: String,
      default: id.generate()
    },
    title: {
      type: String,
      required: true
    },
    creator: {
      type: ObjectId,
      ref: "User"
    },
    description: {
      type: String,
      default: "No description provided."
    },
    company_reviews: {
      name: {
        type: String,
        default: "RSW"
      },
      review: {
        type: String,
        default: "asodsodo"
      },
      rating: {
        type: String,
        default: "10/10"
      }
    },
    employee_reviews: {
      name: {
        type: String,
        default: "Doge Dog"
      },
      company: {
        type: String,
        default: "RSW"
      },
      review: {
        type: String,
        default: "blah blah"
      },
      rating: {
        type: String,
        default: "10/10"
      }
    },
    createdAt: {
      type: String,
      default: moment(new Date()).format("MMM DD, YYYY") // "Sun, 3PM"
    }
  });
  
  var Resume = mongoose.model('Resume', ResumeSchema);
  module.exports = Resume;
  </code></pre>
  
  <hr>
  
  <pre><code>const mongoose = require('mongoose');
  const Schema = mongoose.Schema;
  var moment = require('moment');
  var bcrypt = require('bcrypt');
  var id = require('../../helpers/generator');
  let beautifyUnique = require('mongoose-beautiful-unique-validation');
  
  
  const UserSchema = new Schema({
      _id: {
          type: String,
          default: id.generate()
      },
      firstName: {
          type: String,
          required: true
      },
      lastName: {
          type: String,
          required: true
      },
      accountType: {
          type: String,
          enum: ['Alphaneer', 'Administrator', 'Support', 'PRO'],
          default: 'Alphaneer'
      },
      email: {
          type: String,
          required: true,
          trim: true
      },
      username: {
          type: String,
          required: true,
          trim: true,
          unique: true
      },
      bio: {
          type: String,
          default: "No bio provided."
      },
      password: {
          type: String,
          required: true
      },
      createdAt: {
          type: String,
          default: moment(new Date()).format("MMM DD, YYYY") // "Sun, 3PM 17"
      }
  });
  
  // authenticate input against content from database. BLOODY HELL ITS A MESS
  UserSchema.statics.authenticate = function(email, password, callback) {
      User.findOne({
              email: email
          })
          .exec(function(err, user) {
              if (err) {
                  return callback(err);
              }
              bcrypt.compare(password, user.password, function(err, result) {
                  if (result === true) {
                      return callback(null, user)
                  } else {
                      return callback();
                  }
              })
          })
  }
  
  UserSchema.pre('save', function(next) {
      var user = this;
      bcrypt.hash(user.password, 10, function(err, hash) {
          if (err) throw err;
          user.password = hash;
          console.log("LOG: Password hashed &amp; user saved.");
          next();
      });
  });
  
  var User = mongoose.model('User', UserSchema);
  
  module.exports = User;
  </code></pre>
  
  <hr>
  
  <p>And I want to create a Resume as the logged in user here</p>
  
  <pre><code>// POST /dashboard/resume/create
  router.post('/resume/create', (req, res, next) =&gt; {
    Resume.create(req.body, (err, resume) =&gt; {
      if (err) {
        var err = new Error("Error:" + err);
        err.status = 404;
        next(err);
      } else {
        return res.redirect('/dashboard');
      }
    })
  });
  </code></pre>
  
  <hr>
  
  <p>I also create a Resume when I register a user. Kind of a welcome thing</p>
  
  <pre><code>// POST /register
  router.post('/', (req, res, next) =&gt; {
    var data = {
      firstName: req.body.fName,
      lastName: req.body.lName,
      username: req.body.username,
      email: req.body.email,
      password: req.body.password,
      bio: req.body.bio
    };
    User.create(data, (err, user) =&gt; {
      if (err) {
        throw err;
      }
      var resume = {
        title: "Welcome to NAME!"
      }
      Resume.create(resume, (err, resume) =&gt; {
        if (err) throw err;
        return res.redirect('/');
      });
    });
  });
  </code></pre>
  
  <p>Any help is appreciated and I can also do some further explaining if it isn't making sense :)</p>