Loading lesson path
Python
Connect Python to SQL and document databases for real-world application work.
Python can be used in database applications.
Python can be used in database applications.
To create a database in MySQL, use the "CREATE DATABASE" statement:
To create a database in MongoDB, start by creating a MongoClient object, then specify a connection URL with the correct ip address and the name of the database you want to create.
To create a table in MySQL, use the "CREATE TABLE" statement.
A collection in MongoDB is the same as a table in SQL databases.
To fill a table in MySQL, use the "INSERT INTO" statement.
A document in MongoDB is the same as a record in SQL databases.
To select from a table in MySQL, use the "SELECT" statement:
In MongoDB we use the find() and find_one() methods to find data in a collection.
When selecting records from a table, you can filter the selection by using the "WHERE" statement:
When finding documents in a collection, you can filter the result by using a query object.
Use the ORDER BY statement to sort the result in ascending or descending order.
Use the sort() method to sort the result in ascending or descending order.
You can delete records from an existing table by using the "DELETE FROM" statement:
To delete one document, we use the delete_one() method.
You can delete an existing table by using the "DROP TABLE" statement:
You can delete a table, or collection as it is called in MongoDB, by using the drop() method.
You can update existing records in a table by using the "UPDATE" statement:
You can update a record, or document as it is called in MongoDB, by using the update_one() method.
You can limit the number of records returned from the query, by using the "LIMIT" statement:
To limit the result in MongoDB, we use the limit() method.
You can combine rows from two or more tables, based on a related column between them, by using a JOIN statement.