Mongoose - don't allow documents to have identical arrays
<p>I want to create a database schema where a document cannot have an array that is identical to that of another document. So, say I have the schema <code>conversations</code>:</p>

<pre><code>var ConversationSchema = new Schema({
    name: String,
    participants: {
        type: [{
            type: Schema.Types.ObjectId,
            ref: 'User'
        }]
    }
});
</code></pre>

<p>Now if I create two conversations with the same participants, how can I validate this so that the second one will fail, but the third will not?</p>

<pre><code>var conversation1 = new Conversation({
    name: "Hello",
    participants: ['12345', '09876']
});

var conversation2 = new Conversation({
    name: "World",
    participants: ['12345', '09876']
});

var conversation3 = new Conversation({
    name: "Group chat",
    participants: ['12345', '09876', '13579']
});

conversation1.save(); // Valid
conversation2.save(); // Invalid - conversation already exists
conversation3.save(); // Valid
</code></pre>