Introduction to MongoDB in Python
Donny Winston
Instructor
db.laureates.find_one({
"firstname": "Walter",
"surname": "Kohn"})
{'born': '1923-03-09',
'bornCity': 'Vienna',
'bornCountry': 'Austria',
'firstname': 'Walter',
'prizes': [
{'affiliations': [
{'city': 'Santa Barbara, CA',
'country': 'USA',
'name': ('University of '
'California')
}],
'category': 'chemistry',
'motivation': (
'"for his development of the '
'density-functional theory"'),
'share': '2',
'year': '1998'
}],
'surname': 'Kohn',
...} # showing partial document
db.laureates.count_documents({
"prizes.affiliations.name": (
"University of California")})
34
db.laureates.count_documents({
"prizes.affiliations.city": (
"Berkeley, CA")})
19
db.laureates.find_one({'surname': 'Naipaul'})
{'_id': ObjectId('5b9ec791f35b63093c3d98b7'),
'born': '1932-08-17',
'died': '2018-08-11',
'diedCity': 'London',
'diedCountry': 'United Kingdom',
'diedCountryCode': 'GB',
'firstname': 'Sir Vidiadhar Surajprasad',
'gender': 'male',
'id': '747',
'prizes': [{'affiliations': [[]],
'category': 'literature',
'motivation': ('"for having united perceptive narrative and '
'incorruptible scrutiny in works that compel us '
'to see the presence of suppressed histories"'),
'share': '1',
'year': '2001'}],
'surname': 'Naipaul'}
db.laureates.count_documents({"bornCountry": {"$exists": False}})
31
db.laureates.count_documents({})
922
db.laureates.count_documents({"prizes": {"$exists": True}})
922
db.laureates.count_documents({"prizes.0": {"$exists": True}})
922
db.laureates.count_documents({"prizes.1": {"$exists": True}})
6
Introduction to MongoDB in Python