I am able to execute command from terminal. I have this simple java program
public static void main(String s[]) {
new MongoDb();
}
public MongoDb() {
MongoClient mongoClient = MongoClients.create();//"mongodb://127.0.0.1:27017");
MongoDatabase database = mongoClient.getDatabase("mqtt");
addMqttUser(database);
}
public void addMqttUser(MongoDatabase database) {
MongoCollection<Document> collection = database.getCollection("restaurants");
Document document = new Document("name", "mqtt_user")
.append("username", "test22")
.append("is_superuser", false)
.append("password", "a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3");
collection.insertOne(document, new SingleResultCallback<Void>() {
@Override
public void onResult(final Void result, final Throwable t) {
System.out.println("Inserted!");
}
});
}
I am getting this in my log
11:16:07,842 INFO cluster:71 - Cluster created with settings {hosts=[localhost:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
11:16:07,991 INFO cluster:71 - No server chosen by WritableServerSelector from cluster description ClusterDescription{type=UNKNOWN, connectionMode=SINGLE, serverDescriptions=[ServerDescription{address=localhost:27017, type=UNKNOWN, state=CONNECTING}]}. Waiting for 30000 ms before timing out
I am using 3.4.1 version of mongodb