title: Node.js 400 Bad request
body: <p>I'm stuck with the 400 bad request when trying to POST to my mongo db, not knowing what's wrong with the code.</p>
  
  <p>This is the structure in Mongoose:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var exp = mongoose.model('Exp', {
      _creator: {
          type: mongoose.Schema.Types.ObjectId,
          required: true
      },
  
      exps: [{
          description: {
              type: String,
              required: true
          },
          skillId: {
              type: mongoose.Schema.Types.ObjectId,
              required: true
          }
      }]
  
  });</code></pre>
  </div>
  </div>
  </p>
  
  <p>This is my test case structure and it is how I want the data to be stored:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const exp = {
      _creator: UserOneId, // an ObjectID
      exps:[{
          description: "Ate an apple",
          skillId: SkillOneId // an ObjectID
      },{
          description: "Took a shower",
          skillId: SkillTwoId // an ObjectID
      }],
  
  };</code></pre>
  </div>
  </div>
  </p>
  
  <p>The exps part should be an array to allow storing multiple exps, each with a description and a skill id.</p>
  
  <p>Below is my POST function:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>app.post('/exps', authenticate, (req, res) =&gt; {
  
    var exp = new Exp({
      _creator: req.user._id, // got from suthenticate middleware
      exps: req.body.exps
    });
    exp.save().then(() =&gt; {
      res.send(exp);
    }, (e) =&gt; {
      res.status(400).send(e);
    });
  
  })</code></pre>
  </div>
  </div>
  </p>
  
  <p>and my test case:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>describe('POST /exps', () =&gt; {
      it('Should create new exp', (done) =&gt; {
          request(app)
              .post('/exps')
              .set('x-auth', users[0].tokens[0].token)
              .send(exps)
              .expect(200)
              .end(done);
      })
  });</code></pre>
  </div>
  </div>
  </p>
  
  <p>With a structure like this, I just can't figure out what went wrong that's giving me the 400, middleware &amp; variables not mentioned here have passed with other test cases so I don't think it's those.</p>
  
  <p>The error message in test looks like this:</p>
  
  <pre><code>1) POST /exps Should create new exp:
   Error: expected 200 "OK", got 400 "Bad Request"
    at Test._assertStatus (node_modules/supertest/lib/test.js:250:12)
    at Test._assertFunction (node_modules/supertest/lib/test.js:265:11)
    at Test.assert (node_modules/supertest/lib/test.js:153:18)
    at Server.assert (node_modules/supertest/lib/test.js:131:12)
    at emitCloseNT (net.js:1552:8)
    at _combinedTickCallback (internal/process/next_tick.js:77:11)
    at process._tickCallback (internal/process/next_tick.js:104:9)
  </code></pre>
  
  <p>Any help appreciated.</p>