如何通过 Spring Boot 在 MongoDB 中加载初始数据? [英] How can you load initial data in MongoDB through Spring Boot?
问题描述
是否可以使用 src/main/resources/data.sql
或任何其他文件在 MongoDB
数据库中加载初始数据?
Is it possible to load initial data in a MongoDB
database using src/main/resources/data.sql
or by any other file?
我知道 data.sql
用于 SQL
数据库,而 MongoDB
是 NOSQL
数据库.但只是想知道对于 NOSQL
DB 是否有任何等效的 data.sql
.
I understand that data.sql
is used for SQL
DB's whereas MongoDB
is a NOSQL
DB. But just wanted to know if there is any equivalent of data.sql
for NOSQL
DB's.
在谷歌搜索时我发现了这个 SO 链接(Spring Boot - 加载初始数据) 可以满足我的要求,但它仍然不是一个独立的文件 data.sql
.
While googling I found out this SO link (Spring Boot - Loading Initial Data) which does what I am looking for but still it's not a standalone file data.sql
.
推荐答案
要加载初始数据,您可以使用数据库迁移工具,例如 MongoBee
To load initial data you can use db migration tool like MongoBee
在java中处理数据初始化非常有用的选项.您只需要在 Spring Boot 中配置 @Bean public Mongobee mongobee
并设置组件扫描以获取数据创建实际发生的数据变更日志.
It's very useful option to handle data initialization in java. You just need to configure @Bean public Mongobee mongobee
in your spring boot and setup component scan for data ChangeLogs where data creation actually happens.
这篇关于如何通过 Spring Boot 在 MongoDB 中加载初始数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!