MongoDB not authorized for query admin.system.users

前端 未结 4 707
滥情空心
滥情空心 2021-01-06 16:01

I am bit new to MongoDb and I am using MongoDb v.2.4.Here the problem is that when I run the mongod with --auth parameter, even after authenticating I am not able to perform

4条回答
  •  轮回少年
    2021-01-06 16:37

    Not for the OP, but for those of you landing here on an internet search for

    Failed: error counting admin.system.users: not authorized on admin to execute command { count: "system.users", query: {}, $db: "admin" }
    

    The answer, most likely, is that you need to specify the database name in the connection string. For example, in my case, I was doing a mongorestore, like so

    mongorestore --uri=mongodb+srv://[username]:[password]@[mongo-server] --dir=[backup-file]
    

    And what I needed to do was

    mongorestore --uri=mongodb+srv://[username]:[password]@[mongo-server]/[database-name] --dir=[backup-file]
    

    The same thing would apply to a mongodump. The point is that it tries to connect to the admin DB by default, and that might not be what you're trying to do.

提交回复
热议问题