一、簡(jiǎn)介
非關(guān)系型數(shù)據(jù)庫(kù)(nosql數(shù)據(jù)庫(kù))中的文檔型關(guān)系數(shù)據(jù)庫(kù)
以bson(升級(jí)版json格式)結(jié)構(gòu)存儲(chǔ)數(shù)據(jù)非關(guān)系型數(shù)據(jù)庫(kù)特點(diǎn)
1.數(shù)據(jù)模型比較簡(jiǎn)單.(主要)
2.需要靈活性更強(qiáng)的應(yīng)用系統(tǒng)
3.對(duì)數(shù)據(jù)庫(kù)性能要求較高(主要)
4.不需要高度的數(shù)據(jù)一致性(主要)
5.對(duì)于給定key,比較容易映射復(fù)雜值的環(huán)境.mongodb特點(diǎn)
1:JSON結(jié)構(gòu)和對(duì)象模型接近鸽捻,開(kāi)發(fā)代碼量少
2:JSON動(dòng)態(tài)模型意味著更容易響應(yīng)新的業(yè)務(wù)需求
3:復(fù)制集提供了 99.999%高可用
4:分片架構(gòu)支持海量數(shù)據(jù)無(wú)縫擴(kuò)容每個(gè)文檔大小不能超過(guò)16MB
二、 MongoDB范式化與反范式化
范式化:將數(shù)據(jù)分散到多個(gè)不同的集合泉坐,不同集合之間可以相互引用數(shù)據(jù)格二。如果要修改數(shù)據(jù),只需修改保存這塊數(shù)據(jù)的文檔就行浇雹。但是MongoDB沒(méi)有連接(join)工具,所以在不同集合之間執(zhí)行連接查詢需要進(jìn)行多次查詢硅堆。
反范式化:將每個(gè)文檔所需的數(shù)據(jù)都嵌入在文檔內(nèi)部屿储。每個(gè)文檔都有自己的數(shù)據(jù)副本,而不是所有文檔共同引用一個(gè)數(shù)據(jù)副本渐逃。但是如果數(shù)據(jù)發(fā)生變化够掠,那么所有相關(guān)文檔都需要進(jìn)行更新。
范式化能夠提高數(shù)據(jù)寫(xiě)入速度茄菊,反范式化能夠提高數(shù)據(jù)讀取速度疯潭。
三、Spring Data
Spring Data方法命名規(guī)范
關(guān)鍵字 | 例子 | JPQL |
---|---|---|
And | findByNameAndAge(String name, Integer age) | where name = ? and age = ? |
Or | findByNameOrAge(String name, Integer age) | where name = ? or age = ? |
Is | findByName(String name) | where name = ? |
Between | findByAgeBetween(Integer min, Integer max) | where age between ? and ? |
LessThan | findByAgeLessThan(Integer age) | where age < ? |
LessThanEqual | findByAgeLessThanEqual(Integer age) | where age <= ? |
GreaterThan | findByAgeGreaterThan(Integer age) | where age > ? |
GreaterThanEqual | findByAgeGreaterThanEqual(Integer age) | where age >= ? |
After | 等同于GreaterThan | |
Before | 等同于LessThan | |
IsNull | findByNameIsNull() | where name is null |
IsNotNull | findByNameIsNotNull() | where name is not null |
Like | findByNameLike(String name) | where name like ? |
NotLike | findByNameNotLike(String name) | where name not like ? |
StartingWith | findByNameStartingWith(String name) | where name like '?%' |
EndingWith | findByNameEndingWith(String name) | where name like '%?' |
Containing | findByNameContaining(String name) | where name like '%?%' |
OrderByXx[desc] | findByIdOrderByXx[Desc] (Long id) | where id = ? order by Xx [desc] |
Not | findByNameNot(String name) | where name != ? |
In | findByIdIn(List<Long> ids) | where id in ( ... ) |
NotIn | findByIdNotIn(List<Long> ids) | where id not in ( ... ) |
True | findByXxTrue() | where Xx = true |
False | findByXxFalse() | where Xx = false |
IgnoreCase | findByNameIgnoreCase(String name) | where name = ? (忽略大小寫(xiě)) |