Welcome to My Intro to MongoDB with Python
MongoDB is a tool that helps you explore data without requiring it to have a strict no instructor because of this you can handle diverse data together and unify analytics. You can also keep improving in fix issues as your requirements evolve most application programming interfaces or api's on the web today expose a certain data format if you can express your data in this format then you can get started with MongoDB here's what I mean javascript is the language of web browsers javascript object notation or json is a common way that web services and client code past data json is also the basis of MongoDB data format
So, what is JSON? JSON has two collection structures objects Maps string keys to values and arrays. Order values values in turn are one of a few things values are strings numbers the value true the value false the value null or another object or array that's it these JSON data types have equivalents in Python. JSON objects are like Python dictionaries with string type keys arrays are like Python lists and the values I mentioned also mapped to Python for example null in JSON maps to none in Python
Now, how are these JSON Python types expressed in MongoDB? A database maps names to collections you can access collections by name the same way you would access values in a Python dictionary. A collection in turn is like a list of dictionaries called documents by MongoDB when a dictionary is a value within a document that's a sub document values in a document can be any of the types I mentioned MongoDB also supports some types native to - but not to JSON two examples are dates and regular expressions
Let's make concrete how JSON maps to Python and in turn to MongoDB. Here, we access the Nobel Prize API and collected its data into a database for you first we import the requests library which will get the data from the API we also import the client class from pymongo pi is the official Python driver for MongoDB then we connect to our local database server we say that we want a database with the name Nobel and MongoDB creates it finally we gather JSON responses for the prize and laureate endpoints we insert them into the prizes and laureates collections which MongoDB also creates for me
Now, let's go over how to count documents in a collection and how to find one to inspect. First, a note on accessing databases and collections from a client object one way is square bracket notation as if a client is a dictionary of databases with database names as keys a database in turn is like a dictionary of collections with collection names as keys another way to access things is dot notation databases are attributes of a client and collections are attributes of a database. To count documents, use the count_documents collection method pass a filter document to filter to limit what you count in this case we want an unfiltered total count so we pass an empty document as the filter finally you can fetch a document and infer the schema of the raw JSON data given by the Nobel Prize API use the find_one method again with no filter to grab a document from the collection
Now, let's practice you'll access databases and collections from a connected client you'll count documents and you
"WEBVTTKind: captionsLanguage: enwelcome to my intro to MongoDB with Python MongoDB is a tool that helps you explore data without requiring it to have a strict no instructor because of this you can handle diverse data together and unify analytics you can also keep improving in fix issues as your requirements evolve most application programming interfaces or api's on the web today expose a certain data format if you can express your data in this format then you can get started with MongoDB here's what I mean javascript is the language of web browsers javascript object notation or json is a common way that web services and client code past data json is also the basis of MongoDB data format so what is JSON JSON has two collection structures objects Maps string keys to values and arrays order values values in turn are one of a few things values are strings numbers the value true the value false the value null or another object or array that's it these JSON data types have equivalents in Python JSON objects are like Python dictionaries with string type keys arrays are like Python lists and the values I mentioned also mapped to Python for example null in JSON maps to none in Python now how are these JSON Python types expressed in MongoDB a database maps names to collections you can access collections by name the same way you would access values in a Python dictionary a collection in turn is like a list of dictionaries called documents by MongoDB when a dictionary is a value within a document that's a sub document values in a document can be any of the types I mentioned MongoDB also supports some types native to - but not to JSON two examples are dates and regular expressions let's make concrete how JSON maps to Python and in turn to MongoDB here is how I access to the Nobel Prize API and collected its data into a database for you first I important the requests library which will get the data from the API I also important the client class from pymongo pi is the official Python driver for MongoDB then I connect to my local database server I say that I want a database with the name Nobel and MongoDB creates it finally I gather JSON responses for the prize and laureate endpoints I insert them into the prizes and laureates collections which MongoDB also creates for me now let's go over how to count documents in a collection and how to find one to inspect first a note on accessing databases and collections from a client object one way is square bracket notation as if a client is a dictionary of databases with database names as keys a database in turn is like a dictionary of collections with collection names as keys another way to access things is dot notation databases are attributes of a client and collections are attributes of a database to count documents use the count documents collection method pass a filter document to filter to limit what you count in this case I want an unfiltered total count so I pass an empty document as the filter finally you can fetch a document and infer the schema of the raw JSON data given by the Nobel Prize API use the find one method again with no filter to grab a document from the collection now let's practice you'll access databases and collections from a connected client you'll count documents and youwelcome to my intro to MongoDB with Python MongoDB is a tool that helps you explore data without requiring it to have a strict no instructor because of this you can handle diverse data together and unify analytics you can also keep improving in fix issues as your requirements evolve most application programming interfaces or api's on the web today expose a certain data format if you can express your data in this format then you can get started with MongoDB here's what I mean javascript is the language of web browsers javascript object notation or json is a common way that web services and client code past data json is also the basis of MongoDB data format so what is JSON JSON has two collection structures objects Maps string keys to values and arrays order values values in turn are one of a few things values are strings numbers the value true the value false the value null or another object or array that's it these JSON data types have equivalents in Python JSON objects are like Python dictionaries with string type keys arrays are like Python lists and the values I mentioned also mapped to Python for example null in JSON maps to none in Python now how are these JSON Python types expressed in MongoDB a database maps names to collections you can access collections by name the same way you would access values in a Python dictionary a collection in turn is like a list of dictionaries called documents by MongoDB when a dictionary is a value within a document that's a sub document values in a document can be any of the types I mentioned MongoDB also supports some types native to - but not to JSON two examples are dates and regular expressions let's make concrete how JSON maps to Python and in turn to MongoDB here is how I access to the Nobel Prize API and collected its data into a database for you first I important the requests library which will get the data from the API I also important the client class from pymongo pi is the official Python driver for MongoDB then I connect to my local database server I say that I want a database with the name Nobel and MongoDB creates it finally I gather JSON responses for the prize and laureate endpoints I insert them into the prizes and laureates collections which MongoDB also creates for me now let's go over how to count documents in a collection and how to find one to inspect first a note on accessing databases and collections from a client object one way is square bracket notation as if a client is a dictionary of databases with database names as keys a database in turn is like a dictionary of collections with collection names as keys another way to access things is dot notation databases are attributes of a client and collections are attributes of a database to count documents use the count documents collection method pass a filter document to filter to limit what you count in this case I want an unfiltered total count so I pass an empty document as the filter finally you can fetch a document and infer the schema of the raw JSON data given by the Nobel Prize API use the find one method again with no filter to grab a document from the collection now let's practice you'll access databases and collections from a connected client you'll count documents and you\n"