Hi, this is the another post of a series where i’ll be publishing some samples showing how to work with MongoDB documents with Java.
This post sample consists on a project that uses spring-boot with spring-data-mongo repository, Fongo(an in-memory mongodb representation) and a schedule maintenance job to delete user records.
We will also use NoSqlUnit – a helper library for tests.
For a cleaner document object, we use Lombok.
You can read more about scheduling-tasks in here.
This project uses the same structure of the one in my previous post.
At this point we can run the app and what the logs to see the scheduled job in action.
Having the app running if we run the test ‘testCountAllUsersNotUpdatedOnLast24Hours’
we can check that all users from the dataset ‘five-users.json’ are loaded and when the schedule job runs it deletes all the five records. All records have the property ‘lastUpdated’ with values that exceed more than 24 hours from now.
Sample data to load using NoSqlUnit.
Hope it’s helpful for someone!