在本例中,如果不指定authenticationDatabase参数,数据库将始终尝试根据将要连接到的数据库对用户进行身份验证。如果我们不指定要连接的数据库名称,就像我在上面的示例中所做的那样,服务器将对“test”数据库执行此操作。 2.6.3 通过MongoDB客户端 从MongoDB客户端,我们必须使用这样的连接字符串: mongo://<userName>...
另外,也可以使用mongosh的命令行选项--username、--password、--authenticationDatabase和--authenticationMechanism在连接mongosh时指定身份验证凭证: mongosh --username"myTestDBUser"--password --authenticationDatabasetest--authenticationMechanism SCRAM-SHA-256 ...
要以用户身份进行身份验证,必须提供用户名、密码以及与该用户相关的 authentication database。 重要 无法在同一 mongosh 会话中切换用户。以不同用户身份进行身份验证意味着该会话拥有两个经过身份验证的用户的特权。要在用户之间切换,请退出并重新启动 mongosh。 使用mongosh,您可以在...
# mongo --host 10.10.10.11 --port 27018 --authenticationDatabase admin -u root -p 123456myrs:SECONDARY> show dbs#查看数据库,这里不能查看是因为默认副本节点不能查询数据,需要开启查询权限uncaught exception: Error: listDatabases failed:{"topologyVersion": {"processId": ObjectId("5fb38ca9ae9c791f...
mongo -u admin -p password --authenticationDatabase admin 1. 2. 在连接命令中,使用管理员账号的用户名和密码,并指定认证数据库为admin。成功连接后,可以执行数据库操作。 示例 下面是一个使用账号密码认证的示例。首先,启动MongoDB服务,并开启认证功能。
在用户信息的倒数第二行:"roles" : [ { "role" : "read", "db" : "admin" }, { "role" : "userAdminAnyDatabase", "db" : "admin" } ]表明了tuhooo在这个用户可以有不同数据库的不同权限(这里只有一个库,因为我还没来得及建测试库)。如果两个用户具有相同的名称但是关联到了不同的数据库,那么...
$ mongosh -u Kunwu --authenticationDatabase admin -u/--user:指定用户名 --authenticationDatabase:指定验证数据库。验证数据库,就是创建用户时所处的那个数据库。 然后命令行中会提示你输入密码: 回车确认即可登录: 也可以直接在命令行通过-p/--password来输入密码: ...
$ mongosh -u Kunwu --authenticationDatabase admin 1. -u/--user:指定用户名 --authenticationDatabase:指定验证数据库。验证数据库,就是创建用户时所处的那个数据库。 然后命令行中会提示你输入密码: 回车确认即可登录: 也可以直接在命令行通过-p/--password来输入密码: ...
spring.data.mongodb.port=27017spring.data.mongodb.database=uranus spring.data.mongodb.authentication-database=admin 相关设计: 项目pom.xml添加 <!-- jasypt --> <dependency> <groupId>com.github.ulisesbocchio</groupId> <artifactId>jasypt-spring-boot-starter</artifactId> ...
use admin db.createUser( { user: "myUserAdmin", pwd: "abc123", roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] } ) Connect to the database from shell mongo -u myUserAdmin -p abc123 --authenticationDatabase admin It works. Netdata's module works too. Author ikerfp ...