【问题标题】:How to list all users in the mongo shell?如何列出 mongo shell 中的所有用户?
【发布时间】:2015-12-11 11:37:32
【问题描述】:

在 MongoDB shell 中,如何列出我正在使用的当前数据库的所有用户?
我似乎在 stackoverflow 上的任何地方都找不到它。

【问题讨论】:

    标签: mongodb command mongo-shell


    【解决方案1】:

    你可以这样做:

    db.getUsers()
    

    show users
    

    这两个命令都打印当前数据库的用户列表。请参阅 User Management 的 MongoDB 文档。

    【讨论】:

    • > db.getUsers(); 2018-02-27T06:45:45.853+0500 E QUERY [thread1] 错误:未授权测试执行命令 { usersInfo: 1.0 } :_getErrorWithCode@src/mongo/shell/utils.js:25:13 DB.prototype。 getUsers@src/mongo/shell/db.js:1523:1 @(shell):1:1 > 显示用户; 2018-02-27T06:46:57.428+0500 E QUERY [thread1] 错误:未授权测试执行命令...
    • @flik 也许你需要重置你的 mongodb 用户
    • 我想在此处留下来自@flik 的评论:“已修复:show roles; 然后从列表中添加了角色。”
    • 列出另一个数据库中的用户:db.getSiblingDB('admin').getUsers().
    【解决方案2】:

    列表属于数据库用户:

    use db_namedb.getUsers()show users

    按认证类型列出:

    db.getUsers({ filter: { mechanisms: "SCRAM-SHA-256" } })
    

    带有凭证的列表:

    db.getUsers( {showCredentials: true,  filter: { mechanisms: "SCRAM-SHA-256" }} )
    

    【讨论】:

      【解决方案3】:

      如果您想只列出用户名并留下所有其他批量信息.. 试试

      db.system.users.find({}, {"_id" : 1})
      

      【讨论】:

        猜你喜欢
        • 2014-11-14
        • 1970-01-01
        • 2012-02-10
        • 2017-06-24
        • 1970-01-01
        • 2019-01-25
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多