# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     name: python3
# ---

# + id="dy3f-wbDVvlf"
import pymongo

# + id="r25shoWjV0yF"
sidharth = pymongo.MongoClient("mongodb://<username>:<password>@cluster0-shard-00-00.rd8et.mongodb.net:27017,cluster0-shard-00-01.rd8et.mongodb.net:27017,cluster0-shard-00-02.rd8et.mongodb.net:27017/myFirstDatabase?ssl=true&replicaSet=atlas-232pjm-shard-0&authSource=admin&retryWrites=true&w=majority")

# + [markdown] id="p1hEC8U7EZiN"
# * create a Database:

# + id="2hst6d_kV00-"
db = sidharth["Guvi_assessment"]

# + [markdown] id="mBb1vInOEW4O"
# * create a Collection:
#

# + id="Ui2Zro9wV04g"
col = db["Telephone_Directory"]

# + [markdown] id="meuI8bKyEdQW"
# # create a Directory:

# + id="lOnqqtuSpOFP"
directory = [{"name":"SARAVANAN","department":"REVENUE_department","designation":"SUB_COLLECTOR","mobile":9445000413},
             {"name":"DIVYASHRI","department":"REVENUE_department","designation":"RDO","mobile":9444964899},
             {"name":"RAJASEKAR","department":"RURAL_DEVELOPMENT","designation":"ASST_DIRECTOR ","mobile":7402606005},
             {"name":"KAVITHA","department":"RURAL_DEVELOPMENT","designation":"EXECUTIVE_ENGINEER","mobile":7373704561},
             {"name":"MAHESHWARI","department":"MUNICIPALITY","designation":"COMMISSIONER","mobile":7397372823},
             {"name":"ANANDHAJODHI","department":"MUNICIPALITY","designation":"MUNICIPAL_ENGINEER","mobile":9443439329},
             {"name":"SATHIYASEELAN","department":"HIGHWAYS","designation":"DIVISIONAL_ENGINEER","mobile":9443434004},
             {"name":"RAMESH","department":"PWD","designation":"ENGINEER_WRO","mobile":9884777234},
             {"name":"ARASU","department":"PWD","designation":"ENGINEER_BUILDINGS","mobile":9443991445},
             {"name":"PALANI","department":"HEALTH_department","designation":"DDHS","mobile":9442309909},
             {"name":"ANURADHA","department":"HEALTH_department","designation":"D.O.FOOD_SAFETY","mobile":9443520332},
             {"name":"ABDUL_BHARI","department":"FIRE_AND_RESCUE","designation":"ADO","mobile":9445086137},
             {"name":"SEKAR","department":"TNEB","designation":"SUPERINTENDING_ENGINEER","mobile":9445855444},
             {"name":"KOTEESWARI","department":"TNEB","designation":"AEE","mobile":9445855156},
             {"name":"PREMAVATHY","department":"AGRICULTURE","designation":" DIRECTOR","mobile":9445335303},
             {"name":"GANESAN","department":"AGRICULTURE","designation":"ASSISTANT","mobile":9894215521},
             {"name":"SATHYA_MOORTHI","department":"EDUCATION","designation":"CEO","mobile":9443065779},
             {"name":"ELLAPPAN","department":"EDUCATION","designation":"DEO","mobile":9442630704},
             {"name":"RADHAKRISHNAN","department":"EDUCATION","designation":"DEO","mobile":9444334963},
             {"name":"DHINAKARAN","department":"TRANSPORT","designation":"RTO","mobile":9384808153},
             {"name":"PARVEND","department":"TRANSPORT","designation":"RTO","mobile":9384808145},
             {"name":"SATHISH","department":"FOREST","designation":"DFO","mobile":8919104054},
             {"name":"MALA","department":"SLUM_CLEARANCE_BOARD","designation":"EE","mobile":8637400624},
             {"name":"SASIKUMAR","department":"FACTORIES","designation":"DD_INSPECTOR","mobile":9941186500},
             {"name":"VIMALANADHAN","department":"FACTORIES","designation":"INSPECTOR_OF_LABOUR","mobile":8778619552}
             ]

# + [markdown] id="E5nsYf1rEofx"
# # Insert the record into the collection:

# + id="yZrLSg3RpOIn"
a = col.insert_many(directory)

# + [markdown] id="fn4gn8hREufZ"
# # Make a query to find records you just created:

# + colab={"base_uri": "https://localhost:8080/"} id="M0C72C2a8w6U" outputId="cf8879ed-5686-43dc-849a-351e74d6c750"
for i in col.find({},{"_id":0}):
  print(i)

# + [markdown] id="UAUVTRb9EN60"
# # Modify the records, use the update_one() method:

# + colab={"base_uri": "https://localhost:8080/"} id="oLBI8dwf8w0Q" outputId="4fcea143-0ce4-416a-c67c-31e6e4a9f8da"
# updating the mobile_number & department of Radhakrishnan:

col.update_one({"name":"RADHAKRISHNAN"},{"$set":{"department":"HEALTH_department","mobile":9999555500}})    

# + colab={"base_uri": "https://localhost:8080/"} id="kAhm0NvtFsz5" outputId="fcb69810-5fac-4f2b-c038-9c228a6247a8"
for i in col.find({"department":{"$in":["HEALTH_department","EDUCATION"]}},{"_id":0,"name":1,"department":1,"mobile":1}):
  print(i)

# + [markdown] id="f_nje_dAE75R"
# # Delete the record, use delete_one() method:

# + colab={"base_uri": "https://localhost:8080/"} id="a6HZcRXfE_mp" outputId="2b983b0e-1f1c-4eeb-bcb2-a191ca7d97ff"
# A record belonging to Forest department is deleted:

col.delete_one({"department":"FOREST"})

# + colab={"base_uri": "https://localhost:8080/"} id="9Q4bPlvxJf6m" outputId="93c1ea07-9fdf-479f-9a94-e66fb2e45ac9"
for i in col.find({},{"_id":0,"department":1,"mobile":1}):   
  print(i)

StarcoderdataJupyterScriptsDedupFiltered