当前位置:网站首页> 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数据库管理的文章就介绍到这了。希望对大家的学习有所帮助,也希望大家多多支持软件开发网。
边栏推荐
- [data mining] visual pattern mining: hog feature + cosine similarity /k-means clustering
- 【深度学习】图像超分实验:SRCNN/FSRCNN
- 什么是pv和uv? pv、uv
- Integer learning
- Pat grade a 1103 integer factorizatio
- CTFshow,信息搜集:web9
- CTFshow,信息搜集:web13
- Zhiting doesn't use home assistant to connect Xiaomi smart home to homekit
- Guangzhou Development Zone enables geographical indication products to help rural revitalization
- How bad can a programmer be? Nima, they are all talents
猜你喜欢

In the field of software engineering, we have been doing scientific research for ten years!

Stm32cubemx, 68 sets of components, following 10 open source protocols

C 6.0 language specification approved

Ctfshow, information collection: web12

【深度学习】语义分割实验:Unet网络/MSRC2数据集
![[data mining] visual pattern mining: hog feature + cosine similarity /k-means clustering](/img/a4/7320f5d266308f6003cc27964e49f3.png)
[data mining] visual pattern mining: hog feature + cosine similarity /k-means clustering

Niuke real problem programming - Day10

防火墙基础之服务器区的防护策略

【搞船日记】【Shapr3D的STL格式转Gcode】

CTFshow,信息搜集:web1
随机推荐
What is the process of ⼀ objects from loading into JVM to being cleared by GC?
Ctfshow, information collection: web10
Ctfshow, information collection: web13
[data mining] visual pattern mining: hog feature + cosine similarity /k-means clustering
Niuke real problem programming - Day9
What are the safest securities trading apps
激光雷达lidar知识点滴
15、文本编辑工具VIM使用
MySQL bit type resolution
Stm32f103c8t6 PWM drive steering gear (sg90)
Lidar knowledge drops
时空可变形卷积用于压缩视频质量增强(STDF)
摘抄的只言片语
Shengteng experience officer Episode 5 notes I
#yyds干货盘点# 解决名企真题:交叉线
[follow Jiangke University STM32] stm32f103c8t6_ PWM controlled DC motor_ code
CTFshow,信息搜集:web6
Apache multiple component vulnerability disclosure (cve-2022-32533/cve-2022-33980/cve-2021-37839)
Niuke real problem programming - Day12
Protection strategy of server area based on Firewall