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
May be interested
- How to use Aggregation Pipeline in MongoDBif you are using mongodb's mapreduce, it is best to switch to aggregation pipeline for more efficient computation.
- ObjectId in MongoDByou have seen the use of mongodb objectid in previous chapters. in this chapter, we will understand the structure of objectid.
- Working with Rockmongorockmongo is a mongodb management tool. using it, you can manage your server, database, collection, document, index, .... it provides a very friendly way for users to read, write and create documents. rockmongo is quite similar to phpmyadmin tool for php and mysql.
- Instructions on 2 ways to install MongoDB on Raspberry Piin this tutorial, tipsmake will guide you through the process of installing and setting up the mongodb server software on your raspberry pi.
- Text Search in MongoDBstarting with version 2.4, mongodb started supporting text indexes to search within the string content.
- Replica Set in MongoDBreplication is the process of synchronizing data from multiple servers. replication provides redundancy and increased data availability for multiple data copies on many different database servers. replication protects a database from the loss of a particular server. replication also allows you to recover data from hardware errors or service disconnections. with additional data copies, you can use it for recovery, reporting, or backup.
- How to create a database in MySQLmysql can be a scary program. all commands must go through the command line interpreter program (command prompt) without any intuitive interface. therefore, the basic knowledge of how to create and manipulate on a database in mysql can save you time and avoid nuisance.
- Index (Mong) in MongoDBindex (index) supports the resolution of queries more efficiently. without an index, mongodb must scan through all a collection's document to select the documents that connect to the query command. this scan may be ineffective and requires mongodb to handle a large amount of data.
- How to save React form data in Mongo Databasetry adding mongodb to your web stack to see how easy it is to store and query form data!
- Delete Collection in MongoDBthe db.collection.drop () method in mongodb is used to delete a collection from the database.