用于mongodb的Spring Data 配置

anauzrmj  于 2023-01-25  发布在  Go
关注(0)|答案(2)|浏览(108)

我正在使用spring数据来存储和获取数据库中的记录。最初的数据库是MySQL,但现在我想为mongodb配置相同的应用程序。请为Mysql配置应用程序资源属性。

# ===============================
# = DATA SOURCE
# ===============================
# Connection url for the database connection
spring.datasource.url = jdbc:mysql://localhost:27017/purchase_books

# Username and password
spring.datasource.username = root
spring.datasource.password = root

# Keep the connection alive if idle for a long time (needed in production)
spring.datasource.testWhileIdle = true
spring.datasource.validationQuery = SELECT 1

# ===============================
# = JPA / HIBERNATE
# ===============================
# Show or not log for each sql query
spring.jpa.show-sql = true

# Hibernate ddl auto (create, create-drop, update): with "update" the database
# schema will be automatically updated accordingly to java entities found in the project
spring.jpa.hibernate.ddl-auto = update

# Naming strategy
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy

# Allows Hibernate to generate SQL optimized for a particular DBMS
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect

有人能告诉我mongodb的配置变化吗?

c9x0cxw0

c9x0cxw01#

MySQL是一个关系数据库,MongoDB是一个文档数据库。
Hibernate支持OGM(对象/网格Map器)形式的NOSQL数据库,OGM http://docs.jboss.org/hibernate/ogm/4.2/reference/en-US/html/上的文档
有关Spring、Hibernate和MongoDB https://pragmaticintegrator.wordpress.com/2011/07/14/use-spring-and-hibernate-with-mongodb/,请参考以下示例
此外,如果你使用的是Spring,如果你想删除Hibernate,你可以去Spring MongoTemplate参考下面url https://spring.io/guides/gs/accessing-data-mongodb/中的示例

lyr7nygr

lyr7nygr2#

spring.data.mongodb.uri=mongodb://localhost:27017/<database name>
spring.datasource.username= <username>
spring.datasource.password= <password>

OR数量

spring.data.mongodb.host=localhost
spring.data.mongodb.port=27017
spring.data.mongodb.database=<database name>
spring.data.mongodb.username=<username>
spring.data.mongodb.password=<password>

相关问题