背景
最近项目中用到了Nosql数据库mongodb和SpringMVC框架。随着项目的深入,遇到了一些困难,于是把这些困难的解决记录下来,希望以后能帮助到其他人。
技术介绍
Spring Data MongoDB
Spring Data’s mission is to provide a familiar and consistent, Spring-based programming model for data access while still retaining the special traits of the underlying data store.
Spring Data提供了一套基于Spring的用于数据访问的编程模型。包含了许多模块,我们主要使用的是Spring Data MongoDB模块。
Spring Data for MongoDB is part of the umbrella Spring Data project which aims to provide a familiar and consistent Spring-based programming model for new datastores while retaining store-specific features and capabilities.
Spring Data MongoDB是Spring Data Project的一个模块,提供了一套类似于关系型数据库的接口,并且提供了基于注解的文档存储模式。
MongoDB
MongoDB is a document database with the scalability and flexibility that you want with the querying and indexing that you need
MongoDB 是文档型数据库即所谓的Nosql数据库,存储的数据并不是关系型数据库中有规律的数据,而是使用json格式的文档。
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-k4wOUwHr-1583728111710)(https://github.com/liuleidong...]
使用这种存储格式,MongoDB提供了良好的灵活性和可扩展性。
MongoDB数据库模型
Embedded Data(嵌入型)
嵌入型的数据模型即将所有的信息通过json嵌入文档的方式保存在一个大的文档中,一个文档即保存了所有的信息.这种模型:
一个文档即包含了多个实体之间的关系
由于MongoDB提供的事务是针对单文档的,所以这种存储模型不必担心事务问题
MongoDB针对单个文档的大小有限制,如果数据量太大可能会遇到这个问题
References(引用型)