Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-715

Web support for MongoDB

    XMLWordPrintableJSON

Details

    • Icon: New Feature New Feature
    • Resolution: Won't Fix
    • Icon: Major - P3 Major - P3
    • None
    • None
    • API
    • None

    Description

      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.

      Attachments

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

        Activity

          People

            Unassigned Unassigned
            angelozerr Angelo
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: