I followed this mongodb documentation. Here is my code
public class JMongoDBCDemo
{
MongoClient mongoClient;
DB db;
DBCollection coll;
public
import your Mongo client through "com.mongodb.client.MongoClient"
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import java.util.function.Consumer;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Quick
{
public static void main(String[] args)
{
Logger.getLogger("org.mongodb.driver").setLevel(Level.WARNING);
try (MongoClient mongo = MongoClients.create())
{
mongo.listDatabaseNames().forEach((Consumer) System.out::println);
}
}
}
make sure you have the latest version of the driver, 3.12.2 at the time I wrote this answer
org.mongodb
mongo-java-driver
3.12.2
if the above doesn't work, you're probably using a different logging module, look up how to turn that off, for example if you're using slf4j, create a file named "simpleLogger.properties" inside your resources folder and add this line to it
org.slf4j.simpleLogger.defaultLogLevel = warn