MongoDB使用

 MongoDB常见使用

mongosh

[root@localhost bin]# mongosh
Current Mongosh Log ID: 66a8573ae9521fb76d482f8a
Connecting to:          mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+2.2.12
Using MongoDB:          6.0.16
Using Mongosh:          2.2.12

For mongosh info see: Welcome to MongoDB Shell (mongosh) - MongoDB Shell

------
   The server generated these startup warnings when booting
   2024-07-30T09:58:25.490+08:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
   2024-07-30T09:58:25.490+08:00: You are running this process as the root user, which is not recommended
   2024-07-30T09:58:25.490+08:00: You are running on a NUMA machine. We suggest launching mongod like this to avoid performance problems: numactl --interleave=a                          ll mongod [other options]
   2024-07-30T09:58:25.490+08:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never' in this binary version
   2024-07-30T09:58:25.490+08:00: Soft rlimits for open file descriptors too low
------

show dbs

test> show dbs;

admin   40.00 KiB

config  12.00 KiB

local   72.00 KiB

test> use test

already on db test

show roles

test> show roles

[

  {

    role: 'enableSharding',

    db: 'test',

    isBuiltin: true,

    roles: [],

    inheritedRoles: []

  },

  {

    role: 'dbOwner',

    db: 'test',

    isBuiltin: true,

    roles: [],

    inheritedRoles: []

  },

  {

    role: 'dbAdmin',

    db: 'test',

    isBuiltin: true,

    roles: [],

    inheritedRoles: []

  },

  {

    role: 'readWrite',

    db: 'test',

    isBuiltin: true,

    roles: [],

    inheritedRoles: []

  },

  {

    role: 'userAdmin',

    db: 'test',

    isBuiltin: true,

    roles: [],

    inheritedRoles: []

  },

  {

    role: 'read',

    db: 'test',

    isBuiltin: true,

    roles: [],

    inheritedRoles: []

  }

]

create user

db.createUser({user:"test",pwd:"test",roles:['dbOwner']})

test> db.createUser({user:"test",pwd:"test",roles:['dbOwner']})

{ ok: 1 }

show users

未创建前:

test> show users

[]

创建后:

test> show users

[

  {

    _id: 'test.test',

    userId: UUID('3deb24e1-6ff2-4917-8457-cb51f396e8e1'),

    user: 'test',

    db: 'test',

    roles: [ { role: 'dbOwner', db: 'test' } ],

    mechanisms: [ 'SCRAM-SHA-1', 'SCRAM-SHA-256' ]

  }

]

del user

db.dropUser("用户名")

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

早日实现财富自由 心灵自由

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值