{"id":18686797,"url":"https://github.com/leon/demo-spring-data-mongodb-mock-data","last_synced_at":"2025-06-26T18:34:55.756Z","repository":{"id":142075562,"uuid":"44299223","full_name":"leon/demo-spring-data-mongodb-mock-data","owner":"leon","description":"Load json files into mongodb using Jackson2RepositoryPopulatorFactoryBean","archived":false,"fork":false,"pushed_at":"2015-10-15T06:55:55.000Z","size":116,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-28T00:43:28.418Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/leon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-10-15T06:53:42.000Z","updated_at":"2019-11-28T12:15:24.000Z","dependencies_parsed_at":"2023-03-13T12:50:54.391Z","dependency_job_id":null,"html_url":"https://github.com/leon/demo-spring-data-mongodb-mock-data","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leon%2Fdemo-spring-data-mongodb-mock-data","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leon%2Fdemo-spring-data-mongodb-mock-data/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leon%2Fdemo-spring-data-mongodb-mock-data/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leon%2Fdemo-spring-data-mongodb-mock-data/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leon","download_url":"https://codeload.github.com/leon/demo-spring-data-mongodb-mock-data/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239541853,"owners_count":19656103,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T10:29:09.330Z","updated_at":"2025-02-18T20:23:21.360Z","avatar_url":"https://github.com/leon.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mock Data Demo\nWhen developing applications you often need some data when you start out, and it's always a problem getting it into the\napplication, should you use the domain model to programatically create all the records, should you dump the data directly\ninto the database?\n\nThe following demo does it by using `Jackson2RepositoryPopulatorFactoryBean`\n\n## How?\nplace `.json` files in `src/main/resources/mock-data`, they don't have to be named anything special.\nJust make sure that the get loaded in the correct order, so that the entities that you are trying to link to with\n`@DbRef` exists.\n\n### References?\nOnly the root objects need to have the special `_class` key, so that jackson knows where to start.\n\nSo if you have a embedded object include it as usual\n\n```json\n[\n  {\n    \"_class\": \"se.radley.demo.user.User\",\n    \"id\": \"leon\",\n    \"email\": \"leon@radley.se\",\n    \"firstName\": \"Leon\",\n    \"lastName\": \"Radley\",\n    \"address\": {\n      \"street\": \"my street\",\n      \"city\": \"my city\"\n    }\n  }\n]\n```\n\nIf you need to link to another document via `@DbRef` the other document needs to have a constructor or factory method\nto be able to create the document\n\n```java\n/**\n * Factory constructor for creating DbRefs\n * @param id\n */\nprivate User(String id) {\n    this.id = id;\n}\n\npublic static User ref(String id) {\n    return new User(id);\n}\n```\n\nThat way you can easily create references to objects without having to get the from the db with\n\n```java\n\nUser leon = User.ref(\"leon\");\n\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleon%2Fdemo-spring-data-mongodb-mock-data","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleon%2Fdemo-spring-data-mongodb-mock-data","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleon%2Fdemo-spring-data-mongodb-mock-data/lists"}