Я пытаюсь вставить данные (нагрузочный тест) из jmeter в mongodb, получая неавторизованную ошибку, но соединение с БД. Код подключения:
String mongoUser = "user"
String userDB = "mysyt"
char[] password = "password".toCharArray();
MongoCredential credential = MongoCredential.createCredential(mongoUser, userDB, password);
MongoClientSettings settings = MongoClientSettings.builder()
.applyToClusterSettings {builder ->
builder.hosts(Arrays.asList(new ServerAddress("xxx.xx.xxx.xx",27017)))}
.build();
MongoClient mongoClient = MongoClients.create(settings);
MongoDatabase database = mongoClient.getDatabase("mysyt");
MongoCollection<Document> collection = database.getCollection("user");
vars.putObject("collection", collection);
Error:
Response code:500 Response message:Exception: com.mongodb.MongoCommandException: Command failed with error 13 (Unauthorized): 'command insert requires authentication' on server xx.xxx.xx.xxx:27017. The full response is {"operationTime": {"$timestamp": {"t": 1580126230, "i": 1}}, "ok": 0.0, "errmsg": "command insert requires authentication", "code": 13, "codeName": "Unauthorized", "$clusterTime": {"clusterTime": {"$timestamp": {"t": 1580126230, "i": 1}}, "signature": {"hash": {"$binary": "j7ylgmDSaPsZQRX/SwPTo4ZSTII=", "$type": "00"}, "keyId": {"$numberLong": "6785074748788310018"}}}}
Если я настрою вот так
MongoClient mongoClient = MongoClients.create("mongodb://user:password@xx.xxx.xx.xxx:27017/?authSource=mysyt&ssl=true");
//MongoClient mongoClient = MongoClients.create(settings);
MongoDatabase database = mongoClient.getDatabase("mysyt");
MongoCollection<Document> collection = database.getCollection("user");
vars.putObject("collection", collection);
Ошибка:
Response message:Exception: com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=xx.xxx.xx.xxx:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketWriteException: Exception sending message}, caused by {javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake}, caused by {java.io.EOFException: SSL peer shut down incorrectly}}]
Код вставки:
Имя коллекции настроено в пользовательских переменных (TestPlan)
MongoCollection<Document> collection = vars.getObject("collection");
Document document = new Document("userId", "user1").append("userName", "kohli");
collection.insertOne(document);
return "Document inserted";