当前位置:   article > 正文

Mongodb数据库操作

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> 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

2、查看数据库列表

test> show dbs
admin    40.00 KiB
config  108.00 KiB
local    72.00 KiB
  • 1
  • 2
  • 3
  • 4

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

懒加载创建

test> use atguigu
switched to db atguigu
atguigu> show dbs
admin    40.00 KiB
config  108.00 KiB
local    72.00 KiB
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

4、删除当前数据库

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

在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Guff_9hys/article/detail/907588?site
推荐阅读
相关标签
  

闽ICP备14008679号