<jupyter_start><jupyter_text>Import PyMongo<jupyter_code>import pymongo
pymongo.version
from pymongo import MongoClient<jupyter_output><empty_output><jupyter_text>Connect database<jupyter_code>client=MongoClient('172.17.0.2')
db=client.packt
col=db.embedded<jupyter_output><empty_output><jupyter_text>Insert a document with nested array<jupyter_code>res=col.insert_one({'ages':[30, 42, 12, 19]})
res=col.insert_one({'ages':[18, 27, 25, 19]})<jupyter_output><empty_output><jupyter_text>Match entire array<jupyter_code>col.find_one({'ages': [30, 42, 12, 19] }, {'_id': 0})<jupyter_output><empty_output><jupyter_text>Match on presence of element in array<jupyter_code>col.find_one({'ages':30},{'_id':0})<jupyter_output><empty_output><jupyter_text>Match array with conditions on any elements in array<jupyter_code>col.find_one({'ages':{'$gt':40, '$lt':20}}, {'_id':0})<jupyter_output><empty_output><jupyter_text>Match arraywith conditions on any single element of array<jupyter_code>col.find_one({'ages':{'$elemMatch':{'$lt':22, '$gt':15}}},{'_id':0})<jupyter_output><empty_output><jupyter_text>Match by array index<jupyter_code>col.find_one({'ages.1':42},{'_id':0})<jupyter_output><empty_output><jupyter_text>Match by condition on array index<jupyter_code>col.find_one({'ages.1':{'$gt':40}},{'_id':0})<jupyter_output><empty_output><jupyter_text>Insert a document with nested dictionary<jupyter_code>res=col.insert_one({'personInfo': {'name': 'Alice', 'age': 30}})
res=col.insert_one({'personInfo': {'name': 'Bob', 'age': 42}})
res=col.insert_one({'personInfo': {'name': 'Charlie', 'age': 12}})
res=col.insert_one({'personInfo': {'name': 'David', 'age': 19}})<jupyter_output><empty_output><jupyter_text>Match by name<jupyter_code>col.find_one({'personInfo.name': 'Alice'}, {'_id':0})<jupyter_output><empty_output><jupyter_text>Match by age<jupyter_code>col.find_one({'personInfo.age': {'$gt':40}}, {'_id':0})<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.19751809720785937, 'fraction_numerical': 0.03360910031023785, 'mean_word_length': 14.991735537190083, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, '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': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '322994', 'license': 'MIT', 'n_tokens_mistral': 811, 'n_tokens_neox': 764, 'n_words': 96, 'path': 'bigdata-with-python/pyMongo/query.ipynb', 'repo_name': 'JonhatanHaisi/courses', 'size': '1934'}