Create Database 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.
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
A mask asteroid flies across the Earth About 6 billion years from now, the light from the dying Sun will burn the asteroid belt The MIT team claims to find the most effective way of 'intercepting' meteorites How to create ringtones from Zing MP3 Android 11 amazing benefits of coffee make you irresistible 10 great benefits of Matcha green tea you may not know yet