I'm working on a JavaFX project in IntelliJ using Maven, and now I'm trying to get it to connect to MongoDB. I'm following along an official video from MongoDB doing the same thing, and this is what I added so far. The dependency to my pom file:
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
<version>3.12.7</version>
</dependency>
And the code to connect inside my public static void main
:
public static void main(String[] args) {
String connectionString = "mongodb+srv://admin:javaapp@orderscluster.wcn38.mongodb.net/<dbname>?retryWrites=true&w=majority";
try (MongoClient mongoClient = MongoClients.create(connectionString)) {
MongoIterable<String> strings = mongoClient.listDatabaseNames();
MongoCursor<String> cursor = strings.cursor();
while (cursor.hasNext()) {
System.out.println(cursor.next());
}
}
launch(); // This launches the JavaFX side of the app
}
This is the only code they added in the video, and at this stage it should properly print all the DB names to the console. However I'm getting these 4 errors:
Error:(3,19) java: package com.mongodb.client is not visible
Error:(4,19) java: package com.mongodb.client is not visible
Error:(5,19) java: package com.mongodb.client is not visible
Error:(6,19) java: package com.mongodb.client is not visible
Am I missing something? I can't find much info on this particular error, and I followed the video instructions to a T. Thank you for any help! I really appreciate it.