title: Mongoose Schema validate XOR fields
body: <p>I have the following mongoose schema</p>
  
  <pre><code>var Mongoose = require("mongoose");
  var Schema = Mongoose.Schema;
  
  var headerSchema = new Schema({
      lang : {
          type: String,
          required: true,
          match: [ /^(en|es|pt)$/, "{VALUE} is not a supported language" ],
          index: { unique: true }
      },
      menu : {
          type: [{
              link: { type: Schema.ObjectId, ref: "Link"},
              dropdown: { type: Schema.ObjectId, ref: "Dropdown"},
              autopopulate: true
          }]
      }
  });
  
  headerSchema.plugin(require("mongoose-autopopulate"));
  
  module.exports = Mongoose.model("header", headerSchema);
  </code></pre>
  
  <p>As you might have guessed, this describes a config document for the header of a webpage. This header has a nav (menu in the schema) where each item can be either a dropdown or a link, but not both. Is there a way to add custom validation to my schema to only allow saving the document if either of those is set, but not both and not neither? (think of the boolean operation XOR)</p>
  
  <p>For example, this is a valid header document:</p>
  
  <pre><code>{
    lang: "es",
    menu: [{
      link: {
        title: "Contact",
        href: "/contact"
      }
    }, {
      dropdown: {
       title: "FAQ",
       links: [{
         title: "What is this?",
         href : "/about"
       }]
      }
    }]
  }
  </code></pre>