当前位置:网站首页> MongoD管理数据库的方法介绍
MongoD管理数据库的方法介绍
2022-07-07 13:11:00 【1024问】
今天主要了解数据库管理,在操作之前先把MongoDB服务打开。

如果想查看数据库列表可以使用show dbs.
通过使用MongoDB中内置的句柄db来执行数据库操作。要对不同的数据库操作时,可以使用db.getSiblings(database)方法或use <database>。
db=db.getSiblingDB('testDB')use testDB上面两种方法都把当前数据库句柄切换为testDB,并把db的值设为指定的数据库。
三、创建数据库MongoDB没有提供shell中显示的创建数据库的命令。可以使用<new_database_name>创建一个新的数据库句柄,不过除非把集合添加到新的数据库,否则它实际上并不会被保存。下面的截图中创建一个新的数据库句柄之后执行show dbs时还是显示原来的数据库。添加集合之后才会有新的数据库。

有创建显示肯定会有删除,删除数据库也很简单实用dropDatabase()方法。上面的show dbs可以看到有三个数据库,下面使用dropDatabase()之后看下有几个.
可以看到删除一个之后剩下2个数据库,3-1=2嘛

复制数据库会创建一个除名称外一模一样的数据库,一般作为备份或归档时使用。
创建数据库的副本,可切换到该数据库,然后使用copyDatabase(origin,destination,[hostname])来创建一个副本。origin参数是一个字符串,指定要复制的数据库的名称,destination参数指定在此MongoDB服务器上要创建的数据库名称。可选的hostname参数指定origin数据库MongoDB服务器的主机名(如果从不同的主机复制数据库)。下面的截图是新建一个newDB数据库,里面添加了一个集和Person,然后通过复制数据库创建一个testDB数据库。show collections时可以看到也存在Person集合。

到此这篇关于MongoDB数据库管理的文章就介绍到这了。希望对大家的学习有所帮助,也希望大家多多支持软件开发网。
边栏推荐
- Ctfshow, information collection: web9
- Ffmpeg --- image processing
- STM32F103C8T6 PWM驱动舵机(SG90)
- JSON解析实例(Qt含源码)
- In the field of software engineering, we have been doing scientific research for ten years!
- “百度杯”CTF比赛 2017 二月场,Web:include
- 上半年晋升 P8 成功,还买了别墅!
- Infinite innovation in cloud "vision" | the 2022 Alibaba cloud live summit was officially launched
- Bits and Information & integer notes
- MySQL installation configuration 2021 in Windows Environment
猜你喜欢
随机推荐
PAT 甲级 1103 Integer Factorizatio
[server data recovery] a case of RAID data recovery of a brand StorageWorks server
【深度学习】语义分割实验:Unet网络/MSRC2数据集
Niuke real problem programming - day13
Win10 or win11 taskbar, automatically hidden and transparent
Niuke real problem programming - Day9
[target detection] yolov5 Runtong voc2007 data set
Read PG in data warehouse in one article_ stat
Computer win7 system desktop icon is too large, how to turn it down
Bill Gates posted his resume 48 years ago: "it's not as good-looking as yours."
[server data recovery] data recovery case of raid failure of a Dell server
Pat grade a 1103 integer factorizatio
Novel Slot Detection: A Benchmark for Discovering Unknown Slot Types in the Dialogue System
Lidar Knowledge Drop
Notes HCIA
Today's sleep quality record 78 points
Andriod --- JetPack :LiveData setValue 和 postValue 的区别
Pandora IOT development board learning (HAL Library) - Experiment 12 RTC real-time clock experiment (learning notes)
智汀不用Home Assistant让小米智能家居接入HomeKit
Bits and Information & integer notes








