A Spring tool that allows you to import data in MongoDB from data files on the classpath.
In the future, CSV support will be added.
Coming soon.
To use the tool, you need to instantiate a MongoJSONImporter object. Using Spring, you can instantiate the importer as a bean in the Spring context.
@Bean
public MongoJSONImporter mongoJSONImporter(){
MongoJSONImporter importer = new MongoJSONImporter("mongodb://DBHOST:DBPORT/DBNAME", new DefaultResourceLoader());
return importer;
}
The tool will look for .json files in a 'data' directory on the classpath and create collections with the same name as the file.
The JSON files should define an array of objects. Example:
[
{
"name": "record1Name",
"anotherField": "anotherValue1",
"nestedObject": {
"nestedField:" : 1
}
},
{
"name": "record2Name",
"anotherField": "anotherValue2",
"arrayField": [
"val1",
"val2"
]
},
...
]