Push value to Array if key does not exist Mongoose [duplicate]
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) { ...});