MongoDB is a general-purpose, document-based, distributed database built for modern application developers and the cloud. It is a document database, which means it stores data in JSON-like documents. This is an efficient way to think about data and is more expressive and powerful than the traditional table model.
MongoDB has no separate command to create a database. Instead, it uses the use command to create a database. The use command is used to switch to the specific database. If the database name specified after the use keyword does not exist, then a new database is created with the specified name.
Creating a database using Python in MongoDB
To use Python in MongoDB, we are going to import PyMongo. From that, MongoClient can be imported which is used to create a client to the database. Using the client, a new database can be created.
List of databases using MongoDB shell (before):
Database is created!!
In the above example, it is clearly shown how a database is created. When creating a client, the local host along with its port number, which is 27017 here, is passed to the MongoClient. Then, by using the client, a new database named ‘GFG’ is created.
We can check if the database is present in the list of databases using the following code:
List of Databases in MongoDB shell (after):
- How to create index for MongoDB Collection using Python?
- Python MySQL - Create Database
- Create MySQL Database Login Page in Python using Tkinter
- MongoDB and Python
- Python MongoDB- rename()
- Python MongoDB - Find
- Python MongoDB - bulk_write()
- Aggregation in MongoDB using Python
- Python Mongodb - Delete_one()
- Python MongoDB - Sort
- Python MongoDB - Update_one()
- Python Mongodb - Delete_many()
- Indexing in MongoDB using Python
- Python MongoDB - Query
- How to fetch data from MongoDB using Python?
- Geospatial Queries with Python MongoDB
- Python MongoDB - find_one_and_replace Query
- Python MongoDB - find_one_and_delete Query
- Python MongoDB - insert_many Query
- Python MongoDB - Update_many Query
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.