title: Mongoose schema : SubDocument field only unique per Document
body: <p>I have a little question. I have a User schema which contains a table fields redirecting to the Table schema.
  A Table element can contain a name, I want this name to be unique per User but not between User.</p>
  
  <p>Example:
  User1 -> Table1.name: "foo"
  User2 -> Table1.name: "foo"</p>
  
  <p>But this User1 -> Table2.name: "foo" cannot be possible.</p>
  
  <p>This is the User Schema:</p>
  
  <pre><code>var UserSchema = new mongoose.Schema({
      username: {  type: String, required: true, index: {  
      unique: true } },
      email: {  type: String, required: true, index: {unique: true } },
      password: {  type: String, required: true },
      tables: [{ type: Schema.Types.ObjectId, ref: 'Table' }],
      resetPasswordToken: String,
      resetPasswordExpires: Date,
      uuid: String,                
  });
  </code></pre>
  
  <p>This is the Table schema:</p>
  
  <pre><code>var TableSchema = Schema({
      name: { type: String, required: true, index: { unique: true }},
      logos: [{ type: Schema.Types.ObjectId, ref: 'Logo'}],
  });
  </code></pre>
  
  <p>And this is where I do the queries:</p>
  
  <pre><code>app.post('/newTab', function(req, res){
  
      var use = req.user.username;
      var newTab = new Table({
          name: req.body.name,
      });
  
      newTab.save(function(err, docs){
          if (err) 
          {
              console.error(err);
              res.writeHead(500);
              res.end();
          }
          else
          {
              User.findOne({username: req.user.username}, function(err,  docs) {
                  if(err)  {throw (err);}
                  else
                  {
                      docs.tables.push(newTab);
                      docs.save(function(err, docs){
                          if (err) return console.error(err);
                          res.writeHead(200);
                          res.end(userId);
                      });
                  }
              }); 
          }
      });
  </code></pre>
  
  <p>For now, I cannot add the same table name for two different User ..
  I also tried something with sparse index but can't figure how it works</p>