title: How to save multiple categories for a single post with Mongoose
body: <p>So i have 2 schemas, Game and Category:</p>
  
  <pre><code>const mongoose = require('mongoose');
  const Schema = mongoose.Schema;
  
  const gameSchema = new Schema({
      title: {
          type: String,
          required: true
      },
      description: {
          type: String,
          required: true
      },
      category: [{
          type: Schema.Types.ObjectId,
          ref: 'category'
      }],
  
  });
  
  module.exports = { Game: mongoose.model('game', gameSchema) };
  </code></pre>
  
  <pre><code>const mongoose = require('mongoose');
  const Schema = mongoose.Schema;
  
  const categorySchema = new Schema({
      title: {
          type: String,
          required: true
      },
  });
  
  module.exports = { Category: mongoose.model('category', categorySchema) };
  </code></pre>
  
  <p>I'm trying to save a new Game that contains multiple categories:</p>
  
  <pre><code>const newGame = new Game({
              title: req.body.title,
              description: req.body.postDescription,
              category: req.body.category,
          });
  
          newGame.save().then((game, err) =&gt; {
              if (err) {
                  console.log(err)
              } else {
                  req.flash('success-message', 'New Game Created');
                  res.redirect('/admin/games');
              }
          });
  </code></pre>
  
  <p>And here is my front-end code (handlebars). I'm using tag input plugin for jquery to get an array of categories </p>
  
  <pre><code>&lt;label for="category"&gt;Category&lt;/label&gt;
  &lt;select multiple name="category" id="category" class="cat form-control"&gt;
         {{#select game.category}}
         {{#each categories}}
         &lt;option value="{{title}}"&gt;{{title}}&lt;/option&gt;
         {{/each}}
         {{/select}}
  &lt;/select&gt;
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code> UnhandledPromiseRejectionWarning: ValidationError: game validation failed: category: Cast to Array failed for value "[ 'ACTION','MOBILE','RPG' ]" at path "category"
  </code></pre>
  
  <p>I would like assistance in understanding why this error would occur, thank you.</p>