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
for the second case, is a unique compound index what you're looking for?
db.emails.ensureIndex( {email:1, friends_email:1}, { unique: true } )
As for the first case, I am not sure if there is a way to enforce the first rule. You may need to perform the check on the application side.