0

I have collection of documents, witch has an array, of embedded documents, how i can setup unique key on a field in 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?

1 Answer 1

1

You would need a separate collection holding field4 values, which would act as an index.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.