JEE support (Servlet and JAX-RS) for MongoDB
JavaScript CSS Java XSLT PHP ActionScript
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

What is Mongo JEE?

[Mongo Java Driver] ( gives you the capability to connect and use NoSQL MongoDB with Java code.

Mongo JEE is a JAR which provides simply but usefull Java classes to use this driver in JEE context like using JAX-RS with com.mongodb.DBObject, connect/disconnect to Mongo with ServletContextListener, etc


Here the list of the features provided by Mongo JEE:

JAX-RS support for MongoDB

[JAX-RS support for MongoDB] ( to use Mongo Java structures (DBObject, DBCursor, etc) in the methods of your REST service. Here a sample service which returns the com.mongodb.DBObject :

  	public class ProductService {

  	  	public DBObject findOne(){
  	  	  DB db = mongo.getDB("ecommerce");
  	  	  DBCollection col = db.getCollection("products");
      	  return col.findOne();            

The JAX-RS support provides [several JAX-RS Provider] ( which serialize/deserialize DBObject, DBCursor, etc to JSON stream.

##JSON streaming

JSON streaming : Mongo Java Driver provides com.mongodb.util.JSON helper to serialize DBObject, DBCursor etc to JSON stream but it works only with StringBuilder. Here a sample to write DBObject in HTTP response Write

    HttpServletResponse response = ...
    DBObject o = ...
    // Serialize the JSON DBOBject in a String
    StringBuilder json = new StringBuilder()
    com.mongodb.util.JSON.serialize(o, json);
    // Write the JSON string

Mongo JEE provides com.mongodb.jee.util.JSON which works with Writer/OutputStream:

    HttpServletResponse response = ...
    DBObject o = ...
    // Serialize the JSON DBOBject in the HTTP response Writer
    com.mongodb.jee.util.JSON.serialize(o, response.getWriter());

This idea was suggested to Mongo Java Driver in the JAVA-709 issue


Mongo Java Driver provides com.mongodb.Mongo.Holder helper to hold several static Mongo instances for several Mongo uri. However, this holder doesn't manage deconnection, default Mongo instance.

Mongo JEE provides the com.mongodb.jee.MongoHolder which provides several features like deconnection, default Mongo instance.

Please read Using MogoHolder section for more information.

Initialize Mongo with ServletContextListener

[Initialize Mongo with ServletContextListener] (



When MongoServletContextListener is started it initializes default Mongo connection with com.mongodb.jee.MongoHolder. After that, you can retrieve this Mongo .connection anywhere in your code like this:

  	Mongo mongo = MongoHolder.connect();


Pagination to help pagination with MongoDB and client (like Dojo) to consumes the paginated list.


You can download mongo-jee-1.0.0.jar or use maven :



Apache License, Version 2.0


You can read following articles about Mongo JEE.


Mongo JEE provides the [Mongo JEE Demo with Apache CXF and Dojo] ( which uses the features of Mongo JEE. This demo displays a paginated list of products. This WebApps deploys a JAX-RS REST service ProductsService which returns the paginated JSON products:

WebApps Overview