title: Mongoose: Cast to ObjectId failed for value "ObjectID" at path "red.s1"
body: <p>I have a Mongoose schema that looks like:</p>
  
  <pre><code>const gameSchema = new Schema({
      matchNumber: {
          type: Number,
          required: [true, 'A match must have a number!'],
          unique: true
      },
      red: {
          s1: {
              type: ObjectId,
              ref: 'Match'
          },
          s2: {
              type: ObjectId,
              ref: 'Match'
          },
          s3: {
              type: ObjectId,
              ref: 'Match'
          }
      }
  });
  </code></pre>
  
  <p>And I'm trying to update the document with a Match via Express. On a POST request to  <code>:matchNumber/:alliance/:seed/:teamNumber/match</code>, I do the following:</p>
  
  <pre><code>import * as flatten from 'flat';
  
  let match = req.body;
  const game = await Game.findOneAndUpdate(
      { matchNumber },
      flatten({ [alliance]: { [seed]: match._id } }),
      { new: true }
  );
  </code></pre>
  
  <p>When I make the POST request, I get the following error:</p>
  
  <pre><code>CastError: Cast to ObjectId failed for value "ObjectID" at path "red.s1"
  </code></pre>
  
  <p>I should mention I am using TypeScirpt and this was semi working before but I was encountering the issues mentioned <a href="https://stackoverflow.com/questions/30278445/findoneandupdate-overwriting-attributes-in-2-level-deep-object-passed-as-doc">here</a>, whose solution caused what I am now experiencing.</p>