In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how to create and delete databases in MongoDB. I hope you will learn a lot after reading this article. Let's discuss it together.
1. Create a database in MongoDB
List databases: first check the current database in the system.
First of all, we should know that MongoDB does not provide any commands to create the database. So how will we create the database? The answer is that we don't create a database in MongoDB, we just need to use the database with the name you need and save a single record in the database to create it.
# mongo > show dbs;admin (empty) local 0.078GBtest 0.078GB
Use the new database:
Now, if we want to create a database called exampledb. Simply run the following command and save a record in the database. After saving the first example, you will see that a new database has been created.
> use exampledb; > s = {Name: "TecAdmin.net"} > db.testData.insert (s)
List the databases:
Now, if you list the database, you will see that the new database will be the database named exampledb.
Show dbs;admin (empty) local 0.078GBexampledb 0.078GBtest 0.078GB
2. Delete the database in MongoDB
MongoDB provides the dropDatabase () command to delete the currently used database and its associated data files. Before deleting, make sure which database is selected using the db command.
> dbexampledb
Now, if you execute the dropdatabase () command. It deletes the ExampleDB database.
> db.dropDatabase (); {"dropped": "exampledb", "ok": 1}
To delete the MongoDB database from the Linux command line or from the shell script, use the following command
# mongoexampledb--eval "db.dropDatabase ()" has finished reading this article, I believe you have some understanding of the methods of creating and deleting databases in MongoDB, want to know more about it, welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.