I have the following structure in my Mongo document:
{
property1: 'value',
property2: 'value',
items: [
{
name: 'name1'
},
{
name: 'name2'
},
]
}
Is possible to define a local index over the items array?
In my case, item.name was a unique key but only in this document.
Other documents can have also a item with the same name that a item in other document (but the name in a document cannot be repeated).
Now I'm checking manually if the name is already in use before add/update elements in the document.items array, but if Mongo is capable to do it I will prefer...
EDIT: I have tried to create a index over items.name but if I create that index Mongo doesn't allows to insert/update a item if the name is already defined in other document.