Bootstrap

Mongodb数据库操作

1、进入容器

[root@localhost docker]# docker exec -it mongodb mongosh
Current Mongosh Log ID: 66a8ce38d0b85e052bb78f05
Connecting to:          mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.10.6
Using MongoDB:          7.0.0
Using Mongosh:          1.10.6

For mongosh info see: https://docs.mongodb.com/mongodb-shell/

------
   The server generated these startup warnings when booting
   2024-07-30T10:58:29.512+00:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
   2024-07-30T10:58:29.513+00:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never'
   2024-07-30T10:58:29.513+00:00: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. We suggest setting it to 'never'
   2024-07-30T10:58:29.513+00:00: vm.max_map_count is too low
------

test> 

2、查看数据库列表

test> show dbs
admin    40.00 KiB
config  108.00 KiB
local    72.00 KiB

3、如果数据库不存在,则创建数据库,否则切换到指定数据库

懒加载创建

test> use atguigu
switched to db atguigu
atguigu> show dbs
admin    40.00 KiB
config  108.00 KiB
local    72.00 KiB

4、删除当前数据库

atguigu> db.dropDatabase()
{ ok: 1, dropped: 'atguigu' }
atguigu> 

在这里插入图片描述

;