title: MongoDB E11000 duplicate key error
body: <p>I have a model that keeps erroring out after the first POST. I'm creating a scheduling application, which is X number of days, with rooms, and time slots for the rooms. </p>
  
  <p>The issue I'm having is creating Day Objects in the database. For sake of easy reading I'm just going to have a single key value pair</p>
  
  <p><strong>day.model.js</strong></p>
  
  <pre><code>var mongoose = require('mongoose');
  
  // Day Schema
  var daySchema = mongoose.Schema({
    name:{
      type: String,
      required: true,
    },
    createdAt:{
      type: Date,
      default: Date.now
    }
  });
  
  var Day = module.exports = mongoose.model('Day', daySchema);
  
  // Get all Days
  module.exports.getDays = function(callback, limit){
    Day.find(callback).limit();
  };
  
  // Add Day
  module.exports.addDay = function(day, callback){
    var add = {
      name: day.name,
  };
  Day.create(add, callback);
  };
  </code></pre>
  
  <p><strong>day.routes.js</strong></p>
  
  <pre><code>var express     = require('express');
  var router      = express.Router();
  var jwt         = require('jsonwebtoken');
  var config      = require('../config/database');
  
  Day = require('../models/day.model.js');
  
  // Get all Days
  router.get('/', function(req,res){
    Day.getDays(function(err, days){
      if(err){
        res.send(err);
      }
      res.json(days);
    }); 
  });
  
  // Add Day
  router.post('/create', function(req,res){
    var day = req.body;
    Day.addDay(day, function(err, day){
      if(err){
        res.send(err);
      }
      res.json(day);
    });
  });
  
  module.exports = router;
  </code></pre>
  
  <p><strong>Example JSON</strong></p>
  
  <ol>
  <li><code>{"name": "Monday"}</code>- this will reflect in the Database just fine</li>
  <li><code>{"name": "Tuesday"}</code> - this will throw an 11000 error</li>
  </ol>
  
  <p><strong>Error</strong></p>
  
  <pre><code>{
    "code": 11000,
    "index": 0,
    "errmsg": "E11000 duplicate key error collection: &lt;collection-name&gt;.days index: date_1 dup key: { : null }",
    "op": {
      "name": "Tuesday",
      "_id": "57fd89638039872dccb2230b",
      "createdAt": "2016-10-12T00:52:51.702Z",
      "__v": 0
    }
  }
  </code></pre>
  
  <p>Where I'm confused is I have this same setup for a <strong>User</strong> but when it comes to making a new <strong>Day</strong>, this duplicate key error arises. Not sure what I'm missing or doing wrong. Thanks</p>