How to update if exists otherwise insert new document in javascript/node.js? I am getting as parameter to function dictionary,if dictionary contains _id should update, othe
[db.collection.replaceOne(filter, replacement, options)] with upsert:true
[db.collection.replaceOne(filter, replacement, options)]
upsert:true
E.g. from here:
try { db.restaurant.replaceOne( { "name" : "Pizza Rat's Pizzaria" }, { "_id": 4, "name" : "Pizza Rat's Pizzaria", "Borough" : "Manhattan", "violations" : 8 }, { upsert: true } ); } catch (e){ print(e); }