gpt4 book ai didi

mongodb - 我无法将文档插入到我的远程数据库服务器,出现错误 13(未经授权): 'command insert requires authentication'

转载 作者:行者123 更新时间:2023-12-04 10:49:16 24 4
gpt4 key购买 nike

根据日志,我能够连接到我的远程 Mongo 服务器
使用以下代码:

String mongoUser = vars.get("mongouser");
String userDB = vars.get("userdb");
char[] password = vars.get("password").toCharArray();
MongoCredential credential = MongoCredential.createCredential(mongoUser,
userDB, password);
MongoClientSettings settings = MongoClientSettings.builder()
.applyToClusterSettings {builder ->
builder.hosts(Collections.singletonList(new
ServerAddress(vars.get("mongohost"), vars.get("mongoPort") as int)))}
.build();
MongoClient mongoClient = MongoClients.create(settings);

但是当我插入文档时,出现以下错误:
Response code: 500
Response message: Exception: com.mongodb.MongoCommandException: Command
failed with error 13 (Unauthorized): 'command insert requires authentication'
on server 10.80.47.101:27017. The full response is {"ok": 0.0, "errmsg":
"command insert requires authentication", "code": 13, "codeName":
"Unauthorized"}

请注意,我使用相同的身份验证凭据通过 NOSQLbooster 插入文档并成功。

最佳答案

您正在创建 MongoCredential 的实例但不在 MongoClientSettings 中使用它们(至少我没看到),你需要把它传递给MongoClientSettings.Builder.credential功能

更简单的身份验证示例可以在 MongoDB Performance Testing with JMeter 中找到。文章:

MongoClient mongoClient = MongoClients.create("mongodb://user:password@mongohost/?authSource=userdb&ssl=true");

关于mongodb - 我无法将文档插入到我的远程数据库服务器,出现错误 13(未经授权): 'command insert requires authentication' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59562212/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com