javamongodbmavenslingjackrabbit-oak

How to store Apache Sling content in MongoDB?


I am new to Java and Apache Sling as well. I've been trying to link Sling with MongoDB and these are what I've done so far:

  1. I configured NoSQL MongoDB Resource Provider in Sling console:

NoSQL config

  1. Then the Oak Document Node Store Service:

Oak config

  1. And finally I ran java -Dsling.run.modes=oak_mongo -jar org.apache .sling.launchpad-9.jar -c sling -f - to run the sling launchpad in mongodb mode. This was the results:

Command Prompt

As a result, a database named "sling" was created in MongoDB which I could see via Robo-3T (a MongoDB management tool):

MongoDB

After creating some content through my maven application using the below plugin and deploying it on Sling, I was able to see my newly created nodes and resources in the Sling browser (http://localhost:8080/bin/browser.html):

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <extensions>true</extensions>
            <version>3.3.0</version>
            <configuration>
                <instructions>
                    <Sling-Nodetypes>
                        SLING-INF/nodetypes/nodetypes.cnd
                    </Sling-Nodetypes>
                    <Sling-Initial-Content>
                        SLING-INF/scripts;overwrite:=true;uninstall:=true;path:=/apps/test1/nodes,
                        SLING-INF/content;overwrite:=true;uninstall:=true;path:=/content/test1
                    </Sling-Initial-Content>
                </instructions>
            </configuration>
        </plugin>
    </plugins>
</build>

However, I need to to store everything inside the MongoDB database but currently, nothing stored in the database. How can I achieve this?


Solution

  • The simplest way is to start the Sling Launchpad with the following argument: -Dsling.run.modes=oak-mongo . This will ensure that the Oak is configured to use Mongo. You must remove the sling directory, otherwise the run modes will not be changes.


    What you've done with your attempts is to:

    1. add a new resource provider which shadows the current one at the repository root. I am not sure of the actual effects, it is probably rejected - please see the sling error log
    2. configure a new Oak NodeStoreService which uses Mongo - but it's probably not picked up since there is already a NodeStoreService in action - Sling requires one to start up.