Table of Contents
Use Command in Mongodb: Create Database in Mongodb is easier to understand when the core ideas are paired with practical examples. The sections below explain the topic clearly, highlight useful steps, and point out details that can prevent common errors.
Use command in MongoDB
The use DATABASE_NAME command in MongoDB helps 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 instance,
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
Next lesson: Delete Database in MongoDB
FAQ
What should you know about use command in MongoDB?
The use DATABASE_NAME command in MongoDB helps create the database. This command will create a new database, if it does not exist yet, otherwise, this command will return the existing database.
What is Use Command in Mongodb: Create Database in Mongodb?
Use command in MongoDB The use DATABASE_NAME command in MongoDB helps create the database.
Why is Use Command in Mongodb: Create Database in Mongodb important?
A clear understanding of Use Command in Mongodb: Create Database in Mongodb helps you make informed decisions, avoid common mistakes, and use the relevant tools or techniques more effectively.
Reader Comments 0
Sign in with email or Google to join the discussion.