- 
    Type:Improvement 
- 
    Resolution: Won't Do
- 
    Priority:Major - P3 
- 
    None
- 
    Affects Version/s: None
- 
    Component/s: Index Maintenance, Write Ops
- 
    None
- 
        Query
- 
        None
- 
        None
- 
        None
- 
        None
- 
        None
- 
        None
- 
        None
As far as I can tell this is not possible with the current unique index, but it would be great to be able to unique-index just the keys of an array. This would really help in de-normalization as the following example could act as both a user table and products table if the key of the products array were unique indexed so that keys are unique between all documents in the table.
array(
  '_id' => 1,
  'name' => 'Rita',
  'userdata' => array(...),
  'products' => array(
    1 => array('name' => 'cube', 'style' => 'polka dots'),
    2 => array('name' => 'tiles', 'style' => 'checkerboard')
  )
)
array(
  '_id' => 2,
  'name' => 'Joe',
  'userdata' => array(...),
  'products' => array(
    3 => array('name' => 'circle', 'style' => 'round'),
    4 => array('name' => 'triangle', 'style' => '3-sided')
  )
)
With the current Mongo unique index I could still add the following even though the key already exists within another document:
array(
  '_id' => 3,
  'products' => array(
    3 => array('name' => 'duplicate key', 'style' => 'key is not unique...')
  )
)
- related to
- 
                    SERVER-30191 Add JSON Schema support for document validation -         
- Closed
 
-