Articles in this section

How do I use MongoDB with my Java app?

Java is one of the most popular programming languages in the MongoDB Community. For new users, it’s essential to provide an overview of how to work with the MongoDB Java driver at Upsun.

Java has several frameworks and combinations to work with MongoDB, but it’s important to provide an overview of how to work with the MongoDB Java driver and how to use MongoDB as a Java developer. Therefore, the documentation provides tight integration between Java and MongoDB.

This integration became easier thanks to the Java Config Reader.

MongoDB database = config.getCredential("mongodb", MongoDB::new);
MongoClient mongoClient = database.get();
final MongoDatabase mongoDatabase = mongoClient.getDatabase(database.getDatabase());
MongoCollection<Document> collection = mongoDatabase.getCollection("scientist");
Document doc = new Document("name", "Ada Lovelace").append("city", "London");
collection.insertOne(doc);
Document myDoc = collection.find(eq("_id", doc.get("_id"))).first();

However, we have the option to overwrite the configurations only when it is running at Upsun such as Spring Boot MongoDB and Jakarta EE NoSQL.

 

More Java combinations

We have several articles and source code on this repository:
https://github.com/platformsh/java-quick-start

This repository has several Java combinations it includes Spring, Jakarta EE, MicroProfile, MongoDB, JPA, and so on.

Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.