Show
Introduction to MongoDB DatabaseMongoDB database is defined as create database for database operations, using MongoDB database we are creating the collection into it. MongoDB is not structured database so we have not used create database statement which we have used in other databases like MySQL and PostgreSQL. We can create the database in MongoDB by using the database, use keyword, it is used to create new database in MongoDB, after using the database we are creating the collection into the same. We can create multiple database on single MongoDB server default database which we have used in MongoDB is db. How to Create Database in MongoDB?
Below is the syntax : Syntax:
Below example shows that create new database: Code:
Output:
The below example shows that list as follows: Code:
Output:
Below example shows the same: Code:
Output:
How to Alter Database in MongoDB?Below syntax and example shows that how to alter database:
Syntax:
Below example shows that alter database command to rename the database with new name: Code:
Output:
How to Delete Database in MongoDB?Below syntax and example shows that how to delete the database:
Below syntax shows to drop the database, first we need to connect the specified database which was we are dropping. Syntax:
Given below example shows delete database: Code:
Output:
Below example shows the same: Code:
Output:
ConclusionWe are creating the database by using the use db command, if the database already existed in database then we are connecting to the existing database. We are renaming the database by using the copyDatabase command, also we can drop the database by using dropDatabase command. Recommended ArticlesThis is a guide to MongoDB Database. Here we discuss how to create, alter, delete databases in MongoDB with respective query examples. You may also have a look at the following articles to learn more –
How do I delete all databases in MongoDB?To delete all documents in a collection, pass an empty document ({}). To limit the deletion to just one document, set to true. Omit to use the default value of false and delete all documents matching the deletion criteria.
What is Delete command MongoDB?The delete command removes documents from a collection. A single delete command can contain multiple delete specifications. The command cannot operate on capped collections. The remove methods provided by the MongoDB drivers use this command internally.
How do I drop or delete a collection in MongoDB?You can delete a table, or collection as it is called in MongoDB, by using the drop() method.
How do I delete a table in MongoDB?To delete a MongoDB Collection, use db. collection. drop() command.
|