当前位置:网站首页> 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数据库管理的文章就介绍到这了。希望对大家的学习有所帮助,也希望大家多多支持软件开发网。
边栏推荐
- ⼀个对象从加载到JVM,再到被GC清除,都经历了什么过程?
- Concurrency Control & NoSQL and new database
- Promoted to P8 successfully in the first half of the year, and bought a villa!
- Pat grade a 1103 integer factorizatio
- Why do we use UTF-8 encoding?
- Ctfshow, information collection: web1
- 拜拜了,大厂!今天我就要去厂里
- CTFshow,信息搜集:web10
- 13 ux/ui/ue best creative inspiration websites in 2022
- A need to review all the knowledge, H5 form is blocked by the keyboard, event agent, event delegation
猜你喜欢

Bye, Dachang! I'm going to the factory today

Zhiting doesn't use home assistant to connect Xiaomi smart home to homekit

Win10 or win11 taskbar, automatically hidden and transparent

广州开发区让地理标志产品助力乡村振兴

MySQL bit类型解析

Computer win7 system desktop icon is too large, how to turn it down

IDA pro逆向工具寻找socket server的IP和port

Niuke real problem programming - day13

Jetson AGX Orin CANFD 使用

Stream learning notes
随机推荐
激光雷達lidar知識點滴
一文读懂数仓中的pg_stat
【数据挖掘】视觉模式挖掘:Hog特征+余弦相似度/k-means聚类
buffer overflow protection
Summer safety is very important! Emergency safety education enters kindergarten
Bill Gates posted his resume 48 years ago: "it's not as good-looking as yours."
防火墙基础之服务器区的防护策略
PG基础篇--逻辑结构管理(锁机制--表锁)
@Introduction and three usages of controlleradvice
IDA pro逆向工具寻找socket server的IP和port
Ffmpeg --- image processing
【數據挖掘】視覺模式挖掘:Hog特征+餘弦相似度/k-means聚類
Novel Slot Detection: A Benchmark for Discovering Unknown Slot Types in the Dialogue System
JSON解析实例(Qt含源码)
Several ways of JS jump link
What are the safest securities trading apps
[server data recovery] a case of RAID data recovery of a brand StorageWorks server
Ctfshow, information collection: web4
缓冲区溢出保护
数据库如何进行动态自定义排序?