title: "ERROR:MongoServerError: E11000 duplicate key error collection: myFirstDatabase.files index: key_1 dup key: { key: null }"
body: <p>I'm trying to intergrate in my api the possibility to create a user. I'm using node and mongodb. Here is my schema:</p>
  <pre><code>const mongoose = require('mongoose');
  const Schema = mongoose.Schema;
  
  const FileSchema = new Schema({
      name: {
          type: String,
          required: true,
          minlength:1,
          unique:false,
      }, extension: {
          type:String,
          required:true,
          unique:false,
      }, content: {
          type:String,
          required:true,
          unique:false,
      },group:{
          type:String,
          required:false,
          unique:false,
      }, creator:{
          type: String,
          required: true,
          unique:false,
      }
  })
  
  const File = mongoose.model('File', FileSchema);
  
  module.exports = File;
  </code></pre>
  <p>And here is my function:</p>
  <pre><code>const createNewFile = (req, res) =&gt; {
      const name = req.body.name;
      const extension = req.body.extension;
      const creator = req.body.creator;
      const group = req.body.group;
      console.log(req.body)
  
      const newFile = new File({name, extension, content:'Write your code here',creator, group:group});
  
      newFile.save()
          .then(() =&gt; res.json('200'))
          .catch(err =&gt; res.status(400).json('ERROR:'+err))
  }
  </code></pre>
  <p>And the Insomia and Postman console returns the error that is in the title. What can I do to  avoid this error? I added <code>unique: false</code> because I read it in another quesion , but it failed anyway. Can someone please help me? When the db is empty, I can create the first element. Then, when I create the second one, the errors arrives. PLease help me</p>