title: MongoDB: Unique Key in Embedded Document
body: <p>Is it possible to set a unique key for a key in an embedded document?</p>
  
  <p>I have a Users collection with the following sample documents:</p>
  
  <pre><code> {
         Name: "Bob",
         Items: [
             {
                 Name: "Milk"
             },
             {
                 Name: "Bread"
             }
         ]
      },
      {
         Name: "Jim"
      },
  </code></pre>
  
  <p>Is there a way to create an index on the property Items.Name?</p>
  
  <p>I got the following error when I tried to create an index:</p>
  
  <pre><code>&gt; db.Users.ensureIndex({"Items.Name": 1}, {unique:true});
  E11000 duplicate key error index: GroceryGuruApp.Users.$Items.Name_1  dup key: {
   : null }
  </code></pre>
  
  <p>Any suggestions? Thank you!</p>