<jupyter_start><jupyter_text>Import pymongo<jupyter_code>import pymongo
from pymongo import MongoClient<jupyter_output><empty_output><jupyter_text>Connect to database<jupyter_code>client=MongoClient('localhost')
db=client.packt
coll=db.embedded<jupyter_output><empty_output><jupyter_text>Insert a document with nested array<jupyter_code>res=coll.insert_one({'ages' : [30,42,12,19]})
res=coll.insert_one({'ages' : [18,27,25,19]})<jupyter_output><empty_output><jupyter_text>Match entire array<jupyter_code>coll.find_one({'ages' : [30,42,12,19]},{'_id' : 0})<jupyter_output><empty_output><jupyter_text>Match on presence of element in array<jupyter_code>coll.find_one({'ages' : 30},{'_id' : 0})<jupyter_output><empty_output><jupyter_text>Match array with conditions on any elements in array<jupyter_code>coll.find_one({'ages' : {'$gt':40,'$lt':20}},{'_id' : 0})<jupyter_output><empty_output><jupyter_text>Match array with conditions on any single element of array<jupyter_code>coll.find_one({'ages' : {'$elemMatch' : {'$lt' : 22, '$gt' : 15}}},{'_id' : 0})<jupyter_output><empty_output><jupyter_text>Match by array index<jupyter_code>coll.find_one({'ages.1' : 42},{'_id' : 0})<jupyter_output><empty_output><jupyter_text>Match by condition on array index<jupyter_code>coll.find_one({'ages.1' : {'$gt':40}},{'_id' : 0})<jupyter_output><empty_output><jupyter_text>Insert a document with nested dictionary<jupyter_code>res=coll.insert_one({'personInfo' : {'name' : 'Alice', 'age' : 30}})
res=coll.insert_one({'personInfo' : {'name' : 'Bob', 'age' : 42}})
res=coll.insert_one({'personInfo' : {'name' : 'Charlie', 'age' : 12}})
res=coll.insert_one({'personInfo' : {'name' : 'David', 'age' : 19}})<jupyter_output><empty_output><jupyter_text>Match by name<jupyter_code>coll.find_one({'personInfo.name' : 'Alice'},{'_id' : 0})<jupyter_output><empty_output><jupyter_text>Match by age<jupyter_code>coll.find_one({'personInfo.age' : {'$gt' : 40}},{'_id' : 0})<jupyter_output><empty_output><jupyter_text>Match on multiple conditions<jupyter_code>coll.insert_one({"personInfo":{"name":"Alice","age":32}})
coll.find_one({'personInfo.name':'Alice','personInfo.age':{'$gt':30}},{'_id':0})<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.19708693673190714, 'fraction_numerical': 0.02867546654528903, 'mean_word_length': 12.484662576687116, 'pattern_counts': {'":': 3, '<': 53, '<?xml version=': 0, '>': 53, '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': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '111715', 'license': 'MIT', 'n_tokens_mistral': 920, 'n_tokens_neox': 869, 'n_words': 105, 'path': 'notebooks/ptyhonVideoForBigDataFiles/V09804_Code/Section 2/Video 2.3.ipynb', 'repo_name': 'dguardia/pyhtonForDataScience-David', 'size': '2197'}