Create Database in MongoDB
Use command in MongoDB
The use DATABASE_NAME command in MongoDB is used to create the database. This command will create a new database, if it does not exist yet, otherwise, this command will return the existing database.
Syntax
The basic syntax of the use DATABASE_NAME command is as follows:
use DATABASE_NAME
For example
If you want to create a database named mydb , you use the use DATABASE command as follows:
> use mydb switched to db mydb
To check the currently selected database, you use the db command.
> db mydb
If you want to check the list of databases, use the show dbs command.
> show dbs local 0.78125GB test 0.23012GB
Your created mydb database is not on this list. To display it, you need to insert at least one Collection into it.
> db . movie . insert ({ "name" : "tutorials point" }) > show dbs local 0.78125GB mydb 0.23012GB test 0.23012GB
In MongoDB, the default database is test. If you have not created any databases, then the Collection will be stored in the test.
According to Tutorialspoint
Previous article: Modeling data in MongoDB
Next lesson: Delete Database in MongoDB
You should read it
- MongoDB malicious code attacks more than 26,000 victims in a week
- Learn about security features and authentication in MongoDB
- Create Backup in MongoDB
- Advantages of MongoDB
- Reference Database in MongoDB
- Compare the performance of MongoDB and SQL Server 2008
- Delete Database in MongoDB
- MongoDB queries and tasks you should know
- Index (Mong) in MongoDB
- Instructions on 2 ways to install MongoDB on Raspberry Pi
- ObjectId in MongoDB
- Overview of MongoDB
Maybe you are interested
How to use Auto Clicker Assist to automatically click the mouse
Useful tips to improve your Smart TV experience
How to change the default font in Google Docs - Use the font of choice
This is the culprit that prevents users from updating Windows 11 24H2
What is Facetime? How to use Facetime on iPhone/iPad
How to switch users on the Linux command line