diff --git a/mongodb/.gitignore b/mongodb/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/mongodb/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/mongodb/pom.xml b/mongodb/pom.xml new file mode 100644 index 0000000..3564233 --- /dev/null +++ b/mongodb/pom.xml @@ -0,0 +1,38 @@ + + 4.0.0 + + de.hsma + mongodb + 1.0-SNAPSHOT + jar + + mongodb + + + UTF-8 + 11 + 11 + + + + + org.mongodb + mongodb-driver-sync + 4.9.1 + + + + org.slf4j + slf4j-simple + 2.0.7 + + + + org.junit.jupiter + junit-jupiter-engine + 5.9.2 + test + + + diff --git a/mongodb/src/main/java/org/example/QueryApp.java b/mongodb/src/main/java/org/example/QueryApp.java new file mode 100644 index 0000000..2061478 --- /dev/null +++ b/mongodb/src/main/java/org/example/QueryApp.java @@ -0,0 +1,25 @@ +package org.example; + +import org.bson.Document; +import com.mongodb.client.MongoClient; +import com.mongodb.client.MongoClients; +import com.mongodb.client.MongoCollection; +import com.mongodb.client.MongoDatabase; +import static com.mongodb.client.model.Filters.eq; + +public class QueryApp { + public static void main( String[] args ) { + // Replace the placeholder with your MongoDB deployment's connection string + String uri = "mongodb://localhost:27017"; + try (MongoClient mongoClient = MongoClients.create(uri)) { + MongoDatabase database = mongoClient.getDatabase("mytest"); + MongoCollection collection = database.getCollection("professoren"); + Document doc = collection.find(eq("Name", "Sokrates")).first(); + if (doc != null) { + System.out.println(doc.toJson()); + } else { + System.out.println("No matching documents found."); + } + } + } +} \ No newline at end of file