title: Mongoose: Cannot read property 'where' of undefined, _id
body: <p>I've got that model: </p>
  
  <pre><code>var mongoose = require('mongoose');
  var Schema = mongoose.Schema;
  var uniqueValidator = require('mongoose-unique-validator');
  
  var EquipmentSchema = new Schema({
      model: { type: String, required: true, unique: true},
      price: { type: Number, required: true },
      comments: { type: String },
      market: { type: mongoose.Types.ObjectId, ref: 'Market', required: true },
      category: { type: mongoose.Types.ObjectId, ref: 'Category', required: true },
      make: { type: mongoose.Types.ObjectId, ref: 'Make', required: true },
      rv: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Rv'}],
  });
  
  EquipmentSchema.plugin(uniqueValidator);
  module.exports = mongoose.model('Equipments', EquipmentSchema);
  </code></pre>
  
  <p>This function to save new items: </p>
  
  <pre><code>const Equipments = require('./_models/equipment.model');
  
  var equipmentSaver = function(equipment) {
    return new Promise((resolve, reject) =&gt; {
      console.log(equipment);
      const equipmentToSave = new Equipments({
        _id: equipment.type.model._id,
        market: equipment.type.market._id,
        category: equipment.type.category._id,
        make: equipment.type.make._id,
        model: equipment.type.model.name,
        price: equipment.economicDetails.price,
        comments: equipment.economicDetails.comments,
      });
      equipmentToSave.save()
        .then(result =&gt; resolve(result))
        .catch(error =&gt; reject(error))
     });
  }
  
  module.exports = equipmentSaver;
  </code></pre>
  
  <p>And I'm getting that JSON from the front: </p>
  
  <pre><code>{
    type: {
      market: {
        _id: '5eb1a63926849bed71155592',
        name: 'Healthcare',
        icon: 'local_hospital'
      },
      category: {
        _id: '5eb19f080141dbe4b9aebc9a',
        name: 'Diagnostico por la imagen',
        market: '5eb1a63926849bed71155592'
      },
      make: {
        _id: '5ebd3e107002040000e70e53',
        name: 'GE',
        category: '5eb19f080141dbe4b9aebc9a'
      },
      model: {
        _id: '5ebd3e167002040000e70e54',
        name: 'Voluson S8',
        make: '5ebd3e107002040000e70e53'
      }
    },
    economicDetails: {
      comments: 'Description',
      price: 45000,
      used: false
    }
  }
  </code></pre>
  
  <p>All the <code>_ids</code> are created by the front and I get <strong>these 2 errors</strong>: 
  1.</p>
  
  <pre><code>Error [ValidationError]: Equipments validation failed: _id: Cannot read property 'where' of undefined, model: Cannot read property 'where' of undefined
      at ValidationError.inspect
  at processTicksAndRejections (internal/process/task_queues.js:93:5) {
        message: "Cannot read property 'where' of undefined",
        name: 'ValidatorError',
        properties: [Object],
        kind: 'unique',
        path: '_id',
        value: 5ebd3e167002040000e70e54,
        reason: TypeError: Cannot read property 'where' of undefined
  </code></pre>
  
  <p>2.</p>
  
  <pre><code>MongooseError [ValidatorError]: Cannot read property 'where' of undefined
          at new ValidatorError
  at processTicksAndRejections (internal/process/task_queues.js:93:5) {
        message: "Cannot read property 'where' of undefined",
        name: 'ValidatorError',
        properties: [Object],
        kind: 'unique',
        path: 'model',
        value: 'Voluson S8',
        reason: TypeError: Cannot read property 'where' of undefined
  </code></pre>
  
  <p>I have no idea why. I feel this has something to do with the "unique" character of both these fields but I'm not sure why it throws this error...</p>
  
  <p>EDIT: I've found the origin of the error. When I deleted the <code>EquipmentSchema.plugin(uniqueValidator);</code> from my model, it saves correctly again... 
  I've created an issue on <a href="https://github.com/blakehaswell/mongoose-unique-validator/issues/118" rel="nofollow noreferrer">mongoose-unique-validator's github</a> but if anyone here has had the same problem or even has a solution that'd be great! </p>
  
  <p>Thanks!</p>