Web support for MongoDB

XMLWordPrintableJSON

    • Type: New Feature
    • Resolution: Won't Fix
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: API
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      It doesn't exist "official" support for using MongoDB in Web Apps. I attach my Java code with my idea to help support for Web. To use it, declare the Servlet Context Listener in the web.xml like this :

      ----------------------------------------------
      <listener>
      <listener-class>com.mongodb.web.MongoServletContextListener
      </listener-class>
      </listener>

      <context-param>
      <param-name>mongoURI</param-name>
      <param-value>mongodb://localhost:27017</param-value>
      </context-param>
      ----------------------------------------------

      This listener :

      • on the contextInitialized : initialize the static variable Mongo of the MongoProvider with the "mongoURI" param-value.
      • on the contextDestroyed : close the connection of the static variable Mongo

      Once this listener is started, you can use MongoProvider.getMongo() in any code (Servlet, Filter, Services, etc) to use Mongo.

        1. MongoProvider.java
          0.5 kB
        2. MongoServletContextListener.java
          1 kB

            Assignee:
            Unassigned
            Reporter:
            Angelo
            None
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: