mgenerate4j is a java library that makes generating test data for MongoDB easy.
Rich, representative test data can be generated from a template and loaded directly into MongoDB (or output to a file).
mgenerate4j can generate a wide variety of common data (e.g. names, addresses, emails, ip address) but is easy to extend if you need to do generate something that isn't covered by the out-of-the-box functions.
What does it look like? This is an example of a simple template:
{
"name": "$name",
"age": "$age",
"emails": {
"$array": {
"of": "$email",
"number": 2
}
}
}
And here's what the output might look like:
{
"name": "Jeffery Dooley",
"age": 71,
"emails": ["daisy.monahan@hotmail.com", "jacey.bauch@hotmail.com"]
}
To generate and load documents into MongoDB from a template, the CLI can be used:
$ java -jar mgenerate.jar load --uri "mongodb://localhost:27017" template.json
The full documentation for mgenerate4j can be found here .
mgenerate4j is distributed through Maven Central.
To import as a maven dependency:
<dependency>
<groupId>uk.dioxic.mgenerate</groupId>
<artifactId>mgenerate-core</artifactId>
<version>0.0.7</version>
</dependency>
To import as a gradle dependency:
dependencies {
compile 'uk.dioxic.mgenerate:mgenerate-core:0.0.7'
}
Precompiled executable jars are also available in releases.
Apache 2.0