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
For python:
import pymongo client = pymongo.MongoClient("mongodb_address") db = client.db_name collection = db[collection_name] # update 'data' if 'name' exists otherwise insert new document collection.find_one_and_update({"name": some_name}, {"$set": {"data": some_data}}, upsert=True)