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> 

在这里插入图片描述

  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值