<jupyter_start><jupyter_text>CRUD Operations with Mongo$ mongo> show collections> show dbs> use new_db> db.traffic.insert({'type': 'email', 'user_id': 'test_user' })> db.traffic.find().pretty()> db.traffic.find({'type': 'email'}).pretty()> db.traffic.find({'user_id': 'test_user'}).pretty()> db.traffic.update({'_id': ObjectId()},{'$set': {'type': 'fb'}})> db.traffic.remove({'_id': ObjectId()})> db.traffic.drop()<jupyter_code># Installing PyMongo
#
# sudo pip install pymongo

from pymongo import MongoClient
from bson.json_util import dumps

client = MongoClient()
db = client.new_db_2

# creating a collection
cursor = db.traffic.insert({'type': 'email', 'user_id': 'test_user' })

data = dumps(cursor)

print data
# Query data from collection

cursor = db.traffic.find()

data = dumps(cursor)

print data
# Update document

from bson.objectid import ObjectId

cursor = db.traffic.update({"_id": ObjectId("5aabff494dd49f66b482369c")}, {'$set': {'type': 'fb'}})

data = dumps(cursor)

print data
# Removing document

cursor = db.traffic.remove({'_id': ObjectId('5aabff494dd49f66b482369c')})

data = dumps(cursor)

print data<jupyter_output>{"ok": 1, "n": 1}
{'fraction_non_alphanumeric': 0.18189655172413793, 'fraction_numerical': 0.026724137931034484, 'mean_word_length': 6.4423076923076925, 'pattern_counts': {'":': 3, '<': 4, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '290121', 'license': 'Apache-2.0', 'n_tokens_mistral': 459, 'n_tokens_neox': 434, 'n_words': 95, 'path': 'pymongo.ipynb', 'repo_name': 'surajjana/cbse_cs_ip_notebooks', 'size': '1160'}