开发者

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜