• Increase font size
  • Default font size
  • Decrease font size


mongo4ben is a plugin to access mongoDB with Benerator. It supports data import from and export of generated data to a mongoDB instance and modification of existing database data.



Download and unzip the newest distribution from

Copy the jar files from the distribution's lib folder into your Benerator installation's lib folder.

If you want to distribute a mongoDB data generation project to run on a fresh Benerator installation, put the jars mentioned above into a 'lib' folder inside your project folder. 



If you are not familiar with benerator, learn more about it at

At the beginning, import mongo4ben features in your Benerator project:

    <import platforms='mongodb' />

Then, a mongodb instance can be declared using a <mongodb> element, using an environment definition file:

    <mongodb id='db' environment='mymongo' />

The environment definition file has to be in the project folder or at ${user.home}/databene/ and has to carry the name specified in the <mongodb> declaration before, in this case with content like this:


The db_catalog setting has to be set to mongoDB's database name.

That's it! Now you can use mongodb for data import and export.


A simple data generation example to help you get started. It generates 100 users with 1 to 3 addresses: 

    <import platforms='mongodb' />
    <mongodb id='db' environment='mymongo' />
    <generate type='mit_user' minCount='100' consumer='db'>
        <attribute name='name' type='string' />
        <attribute name='age' type='int' min='18' max='78' />
        <part name='addresses' container='list' count='2'>
            <attribute name='street' pattern='[A-Z][a-z]{4} Street'/>
            <attribute name='houseNo' type='int' min='2' max='9' />


An example that exports (prints) all user data to the text console:

    <import platforms='mongodb' />
    <mongodb id='db' environment='
mymongo' />
    <iterate type='mit_user' source='db' consumer='ConsoleExporter'/>


An trivial anonymization-style example that sets each user's age to 33 and house number to 123:

    <import platforms='mongodb' />
    <mongodb id='db' environment='
mymongo' />
    <iterate type='mit_user' source='db' consumer='db.updater(),ConsoleExporter'>
        <attribute name='age' constant='33' />
        <part name='addresses' source='mit_user' container='list'>
            <attribute name='houseNo' constant='123' />



mongo4ben does not yet support selective queries - all data import refers to the collection by the specified 'type' name and iterates through all elements.



- Java 1.6+
- Benerator 0.7.6+