开发者

How to setup unique index on an element in embeded array of elements

开发者 https://www.devze.com 2023-01-28 23:56 出处:网络
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?

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消