How to setup unique index on an element in embeded array of elements
I have collection of documents, witch has an array, of embedded documents, how i can setup unique key on a field i开发者_如何学JAVAn these array?
example collection
{
field:1
field2: [
{field3:1, field4:4},
{field3:1, field4:5},
]
}
i would like to ensure that "field4" of array "field2" is unique across all documents in collection?
You would need a separate collection holding field4 values, which would act as an index.
精彩评论