title: MongoDB E11000 duplicate key error collection with no unique field in schema
body: <p>I'm setting up a simple blog form with title, content, and <code>json base64</code> image data to pass to a local MongoDB server. This is my post route:</p>
  <pre><code>router.post('/:userName/posts/new', isAuthenticated, async (req, res) =&gt; {
      let parsedImage = req.body.file != null &amp;&amp; req.body.file != '' ? JSON.parse(req.body.file).data : ''
  
      const newPost = new Post({
          title: req.body.title,
          content: req.body.content,
          imageJson: parsedImage
      })
  
      try {
          await newPost.save()
          res.redirect(&quot;/account&quot;)
      } catch (e) {
          console.log(e)
          res.redirect(&quot;/home&quot;)
      }
  })
  </code></pre>
  <p>And this is my schema model:</p>
  <pre><code>const mongoose = require('mongoose');
  
  const postSchema = new mongoose.Schema({
      title: {
          type: String,
          required: true,
      },
      content: {
          type: String,
          required: true,
      },
      imageJson: {
   
  
             type: String
          }
  });
      
      module.exports = mongoose.model('Post', postSchema)
  </code></pre>
  <p>no <code>unique: true</code> as you can see. The first time I tried running this, it ran perfectly, redirecting directly to the /account page, as intended in the try catch block. But, on a second attempt, using a different image, different content, and different title, it threw this error:</p>
  <pre><code>MongoError: E11000 duplicate key error collection: fullstacksus.posts index: userName_1 dup key: { userName: null }
  </code></pre>
  <p>I have no idea what's going on since userName is a database name used in my user account <code>route</code>, but not in my post-making <code>route</code>. Why is it showing up again? Thanks for your answers.</p>