MongoDB 教程
不管我們學(xué)習(xí)什么數(shù)據(jù)庫都應(yīng)該學(xué)習(xí)其中的基礎(chǔ)概念,在mongodb中基本的概念是文檔、集合、數(shù)據(jù)庫,下面我們挨個介紹。
下表將幫助您更容易理解Mongo中的一些概念:
SQL術(shù)語/概念 | MongoDB術(shù)語/概念 | 解釋/說明 |
---|---|---|
database | database | 數(shù)據(jù)庫 |
table | collection | 數(shù)據(jù)庫表/集合 |
row | document | 數(shù)據(jù)記錄行/文檔 |
column | field | 數(shù)據(jù)字段/域 |
index | index | 索引 |
table joins | ? | 表連接,MongoDB不支持 |
primary key | primary key | 主鍵,MongoDB自動將_id字段設(shè)置為主鍵 |
通過下圖實(shí)例,我們也可以更直觀的了解Mongo中的一些概念:
一個mongodb中可以建立多個數(shù)據(jù)庫。
MongoDB的默認(rèn)數(shù)據(jù)庫為"db",該數(shù)據(jù)庫存儲在data目錄中。
MongoDB的單個實(shí)例可以容納多個獨(dú)立的數(shù)據(jù)庫,每一個都有自己的集合和權(quán)限,不同的數(shù)據(jù)庫也放置在不同的文件中。
"show dbs" 命令可以顯示所有數(shù)據(jù)的列表。
$ ./mongo MongoDB shell version: 3.0.6 connecting to: test > show dbs local 0.078GB test 0.078GB >
執(zhí)行 "db" 命令可以顯示當(dāng)前數(shù)據(jù)庫對象或集合。
$ ./mongo MongoDB shell version: 3.0.6 connecting to: test > db test >
運(yùn)行"use"命令,可以連接到一個指定的數(shù)據(jù)庫。
> use local switched to db local > db local >
以上實(shí)例命令中,"local" 是你要鏈接的數(shù)據(jù)庫。
在下一個章節(jié)我們將詳細(xì)講解MongoDB中命令的使用。
數(shù)據(jù)庫也通過名字來標(biāo)識。數(shù)據(jù)庫名可以是滿足以下條件的任意UTF-8字符串。