Showing posts from February, 2016

Java, Mongo - Update array element

(based on schema)

Mongo - Select max field (aggregate, $project, $macth)

(based on schema)

Play Framework - Get current controller path programmatically

Problem:Get the current path from the inside the controller method

Java MongoDB - Commands

Queries only the "productID" and "@type" fields from all the collection documents: BasicDBObject fields = new BasicDBObject();
query.put("productID", 1);
query.put("@type", 2);

BasicDBObject allQuery = new BasicDBObject();

DBCursor cursor = mongoDatasource.getMongoDatasource().find(allQuery, fields);

while(cursor.hasNext()) {
DBObject document =;

{ "_id" : { "$oid" : "56c6c9e0612eb61e88166894"} , "@type" : "Product" , "productID" : "1"}

Adding a new node to an exisitng array BasicDBObject query = new BasicDBObject().append("productID", String.valueOf(productId));
DBObject listItem = new BasicDBObject("offers.offers", newValue);
BasicDBObject update = new BasicDBObject().append("$push", listItem);
mongoDatasource.getMongoDatasource().update(query, update, false, true);

My mongoDB commands

Lists all mongo databases show dbs
Switches to a database use <database_name>
Lists all database collections show collections
Deletes all collection content db.<collection_name>.remove({})
Selects documents having offers with sub-type SingleOffer db.<collection_name>.find({"offers.@type":"SingleOffer"}})
Displays all collection content db.user.find()
Select with AND db.user.find({"offers.offers.offerID":"1", "productID":"1"})
Single field update  The follwing command updates the type of the nested under offer
{"_id" : "1", "offer" : { "@type" : "foo",(...)} db.user.update({"_id":"1"}, {$set:{"foo.@type":"bar"}})

Avro - Defining nested types

Avro serialization schema:

Play - Synchronous server calls with Jersey

Synchronous server calls with Jersey

Edit your build.sbt:

Edit your Java client class:

Spring - Asynchronous rest call to a server

Implement a TaskService class responsible for running the asynchronous processing:

Implement the calling code for the above TaskService:

Eclipse - Missing Maven Dependencies

Problem: Missing project "Maven Dependencies" event after trying to add them through the project "Build path".
Solution: Right click over the project settings"Maven""Update Project..."

Java - javax naming NameNotFoundException DefaultDS not found

Problem: play javax.naming.NameNotFoundException: DefaultDS not found
Solution: Make sure you include an jndiName to you database configuration, for example:

    "db" : { "default" : { "driver" : com.mysql.jdbc.Driver }},
    "db" : { "default" : { "url" : "jdbc:mysql://<database_name>" }},
    "db" : { "default" : { "username" : <username> }},
    "db" : { "default" : { "password" : <password> }}.
    "db" : { "default" : { "jndiName" : DefaultDS }},

Play - No Persistence provider for EntityManager named defaultPersistenceUnit

Problem: play No Persistence provider for EntityManager named defaultPersistenceUnit
Solution: Make sure your file persistence.xml is inside a conf/META-INF subfolder (<project_root>/conf/META-INF/persistence/xml)