1.安裝
創(chuàng)建 文件 /etc/yum.repos.d/mongodb-org-3.4.repo
輸入以下內(nèi)容并保存
[mongodb-org-3.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc
yum install -y mongodb-org
2.正則表達(dá)式查找
> db.users.find({'name':/vison/})
> db.users.find({'name':/^vison/})
- mongodb 可以為前綴型正則表達(dá)式查詢創(chuàng)索引
3.范式和反范式
- 信息更新頻繁還是信息讀取頻繁?
- 更新頻繁 范式化
- 讀取頻繁 反范式化
| 更適合內(nèi)嵌 | 更適合引用 |
|---|---|
| 子文檔較小 | 子文檔較大 |
| 數(shù)據(jù)不會定期改變 | 數(shù)據(jù)經(jīng)常改變 |
| 最終數(shù)據(jù)一致即可 | 中間階段的數(shù)據(jù)必須一致 |
| 文檔數(shù)據(jù)小幅增加 | 文檔數(shù)據(jù)大幅增加 |
| 數(shù)據(jù)通常需要執(zhí)行二次查詢才能獲得 | 數(shù)據(jù)通常不包含在結(jié)果中 |
| 快速讀取 | 快速寫入 |