 <p>Re-read the <code>$set</code> documentation <a href="https://docs.mongodb.org/v3.0/reference/operator/update/set/" rel="nofollow">https://docs.mongodb.org/v3.0/reference/operator/update/set/</a> It specifically says it will replace what is there. So it doesn't care if a document exists or not that's why it doesn't return the error. you need additional operators to reject the query if it exists and is the same. </p> <p><strong>edit/update to below comment</strong></p> <p>You have to trigger the error in order to know if the DB as the collection already and if it's up to date. So an additional operator is required to check if the collection found already has the updated information. MongoDB uses operators represented with <code>$</code> so <code>$gt or $lt or $nor</code> (greater than , less than, Select everything but this) there's more but i'll let you explore the possibilities. <a href="https://docs.mongodb.org/v3.0/reference/operator/query/nor/" rel="nofollow">https://docs.mongodb.org/v3.0/reference/operator/query/nor/</a></p> <p><strong>this line</strong> needs to trigger the error based on your expressions and operators. when you get that working don't just throw the error allow the program to continue to the next because this error isn't meant to break (throw) on that error it's only there to tell you hey the DB has this and it's updated, and on error will let you know nothing was done.</p> <p><code>collection.updateOne(query, {"$set": data},{w: "majority"},function (err,result){ console.error(err);console.log(result); });</code></p>