Hello Everybody i’m so sorry to ask but i’ve been trying to look for an answer for MONTHS, and im already desperate because i can’t seem to find what i need till the point that i’m almost giving up with NoSQL.
So here’s my Schema.
I have States of a Country and they have their non-repeatable ISO CODE,
{
code: 'US-NY',
name: 'New York',
cities: [ ]
},
etc ..
… however inside the state (nested objects) we have cities:
cities:[
{
code: 'new-york',
name:'New York',
},
{
code: 'bufalo',
name:'Búfalo',
},
]
So when i add a document, i want to avoid duplicated nested objects (cities) with the same code (example: ‘bufalo’) within the same document (state).
BUT i could use ‘bufalo’ in another document (state).
When i set an index to cities.code to be Unique, it applies in the whole collection, and i want to use that code in another document.
I would like to repeat ‘bufalo’ city code in another document (state), but i dont want it to be repeated in the same document.
How could i archive this? Thank you so much for your kind help, i will be checking this post desperately.
Thanks
Alan D.
