#Java #MongoDB #Morphia #Map-Reduce

Map-Reduce with MongoDB and Morphia

Just a note to record the usage of Map-Reduce with MongoDB and Morphia. Firstly, add the Morphia dependency. <dependency> <groupId>org.mongodb</groupId> <artifactId>mongo-java-driver</artifactId> <version>2.11.2</version> </dependency> <dependency> <groupId>org.mongodb.morphia</groupId> <artifactId>morphia</artifactId> <version>0.105</version> </dependency> The syntax of MapReduceCommand in Morphia as shown in MapReduceCommand.java: public MapReduceCommand( DBCollection inputCollection, String map, String reduce, String outputCollection, OutputType type, DBObject query) { // Compiled Code } Here we want to group the sales amount (i.e., subtotal) of each county and exclude the null-subtotal from collection. ...

Author 2 min
#Java #MongoDB

Using the MongoDB Aggregation Framework via MongoDB Asynchronous Java Driver

Introduction I often use Morphia in projects for mapping Java objects to/from MongoDB and it’s Query API instead of building the complex DBObject query. However, the current version (v. 0.105) without aggregate command support. Fortunately, the MongoDB Asynchronous Java Driver provides the aggregate builder to construct complex pipelines of operators in fluent way. As usual, the following paragraphs will express some basic usages of mongodb-async-driver in aggregation pipeline framework through an example. ...

Author 3 min
#MongoDB #Morphia #Java #NoSQL

Using MongoDB with Morphia

Morphia - The JVM Object Document Mapper for MongoDB. MongoDB is an extremely useful document-based database in NoSQL field. There are various drivers and client libraries in MongoDB Ecosystem and detailed manual to facilitate the developers to get into it shortly. In the beginning, we use MongoDB Java driver to manipulate CRUD operations on databases. Everything is running well but lots of BasicDBObject cause the code lack of readability and fluency. ...

Author 3 min
#Java #Jersey #Maven

Jersey Test Framework with Maven

Introduction This memo records the issues while executing the unit-test with Jersey Test framework. We use the Jersey framework to implement the RESTful Web services and employ the Maven to manage the dependencies in project. First of all, we add the jersey-test-framework-grizzly2 dependency to enable the test framework in pom.xml; Second, we deploy the application using Jersey specific servlet in web.xml. Finally, we have the following java files within Maven Archetype – maven-archetype-webapp: ...

Author 4 min
#Java #Jersey #Restful

A Jersey POJOMapping Example in Mapping Form Parameters

Jersey, RESTful Web Services in Java. In Java Servlet circumstance, we usually harvest the form parameters by using request.getParameter(“FORM_FIELD_NAME”) syntax. Now we can do it more elegant while enabling Jsersey’s POJOMapping features. The following example demonstrates the account registration scenario. Here we have a Account class, i.e., Account.java: public class Account { private String email; @JsonProperty("email") public String getEmail() { return email; } public void setEmail(String email) { this. ...

Author 2 min