I don't know how to exactly explain my question in title. Sorry for that.
Here is what I mean: I have user model
var userSchema = new Schema({
username: { type: String, required: true },
messages: { type: Number, required: true, default: 0 },
noticed: { type: Date, required: true, default: Date.now },
chatId: { type: Number, required: true }
})
username
and chatId
may be not unique, but there should be no users which username
and chatId
both are the same!
Meaning of this is that there can not be two users with the same username in one chat. But user may be in many different chats. How do I do it in mongoose?