What’s the best way of doing that on Platform?
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 Platform.sh.
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 Platform.sh such as Spring Boot MongoDB and Jakarta EE NoSQL.
Articles
- Spring MVC and MongoDB: a match made in Platform.sh heaven
- Jakarta NoSQL with MongoDB Part 1
- Jakarta NoSQL with MongoDB Part 2
- Quarkus and MongoDB
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.