Using Mongoose / MongoDB $addToSet functionality on array of objects
You need to use the $ne operator. var data = { ‘kind’: ‘tortoise’, ‘hashtag’: ‘foo’ }; Model.update( { ‘articles.hashtag’: { ‘$ne’: ‘foo’ } }, { ‘$addToSet’: { ‘articles’: data } } ) This will update the document only if there is no sub document in the “article” array with the value of hashtag equals to … Read more