var SomeSchema = new Schema({
// ...
members: [
{
name: String,
username: String
}
]
});
//You could check for the username in the condition part of the update query:
var conditions = {
_id: id,
'members.username': { $ne: 'something' }
};
var update = {
$addToSet: { members: { name: 'something', username: 'something' } }
}
SomeModel.findOneAndUpdate(conditions, update, function(err, doc) {
...
});