MongoDB Quick Notes
Mac
1 | $ brew update # 更新 brew |
基本對照
| SQL | MongoDB |
|---|---|
| database | database |
| table | collection |
| row(record) | documents |
| column | field(key) |
| value | value |
Mongo shell
db當前使用的資料庫。show dbs資料庫列表。show collections資料表清單。use [dbname]切換使用目標資料庫。db.getSlibingDB('dbname')取得資料庫參考物件。db.dropDatabase()# 移除資料庫。db.addUser( { user: "<user>", pwd: "<password>", roles: [<roles>] } )# 加入使用者db.auth('id', 'pwd')# 登入認證身份。printjson(obj)將物件以 JSON 格式輸出。db.createCollection(name, {capped: <Boolean>, autoIndexId: <Boolean>, size: <number>, max <number>} )# 建立集合,主要的功能是用來開固定式集合,固定式集合不能刪除 Row,但可以移除整個資料表,一旦capped設為true就要指定size,但如果要限制則必須在指定max。一旦超出max舊的資料就會被覆寫。db.collection.drop()# 移除資料表。db.collection.ensureIndex({name: [1|-1]})# 建立索引db.collection.getIndexes()# 取得索引db.collection.dropIndex({name: 1})# 移除索引
其他資料
snapshot
Performance
Munin
Indexes
B+Tree
Distributed System
Aggregate
SQL 到 MongoDB 對應表
Basic toturial