1. Introduction

The MongoDB cache store persists data in MongoDB. To communicate with the MongoDB server instance, we are using the official java driver version 3.0.4 To configure the cache store, you just need to add a new entry into the persistence section.

1.1. Sample usage

Here is an example for your xml configuration file:

infinispan.xml
<persistence>
   <mongodbStore xmlns="urn:infinispan:config:mongodb:8.2" >
        <connection uri="mongodb://mongoUser:mongoPass@server1:27017,server2:27017/database?w=0&amp;connectTimeoutMS=2000" collection="infispan_cachestore"/>
   </mongodbStore>
</persistence>

If you prefer the programmatic API here is a snippet:

ConfigurationBuilder b = new ConfigurationBuilder();
b.persistence().addStore(MongoDBStoreConfigurationBuilder.class)
   .connectionURI( "mongodb://localhost" )
   .collection( "indexes" );

final Configuration config = b.build();

The connection section contains the connection information to connect to the MongoDB server instance. The authentication section is optional, it allows you to specify username and password if you are using some. The storage section explicits where you will store the data.

property usage default value

connectionURI

The MongoDB connection string.

mongodb://localhost

collection

The collection which will contain the elements.