I have a collection with fields \"email\" and \"friends_email\". I would like to setup a unique-ness constraint like the following, using MongoDB:
No record
You can have compound unique index on email
and friends_email
field for ensuring the second case. But for the first case you need to handle that in the application code or use a java mapper such as Morphia to have a field-based validation. You might wanna check the following post also:
How to apply constraints in MongoDB?