I write this script for insert a doc into Mongodb if not duplicated
import tldextract
from pymongo import MongoClient
client = MongoClient()
db = client.my_domains
collection = db.domain
with open('inputcut.csv', 'r') as f:
for line in f:
ext = tldextract.extract(line)
domain = {"domain":ext.registered_domain}
collection.update(domain,{'upsert':True})
When I run the script, no domains are inserted into the database. I would like to insert a domain if it is not yet present in mongodb. If the domain is already present, we do not insert it and we go to the next one ...
Thank you in advance for your help.