標籤:show dex 成功 system 索引 style writer options result
MongoDB 建立集合
1.手動建立:
文法格式:
db.createCollection(name, options)
參數說明:
- name: 要建立的集合名稱
- options: 選擇性參數, 指定有關記憶體大小及索引的選項
options 可以是如下參數:
| 欄位 |
類型 |
描述 |
| capped |
布爾 |
(可選)如果為 true,則建立固定集合。固定集合是指有著固定大小的集合,當達到最大值時,它會自動覆蓋最早的文檔。 當該值為 true 時,必須指定 size 參數。 |
| autoIndexId |
布爾 |
(可選)如為 true,自動在 _id 欄位建立索引。預設為 false。 |
| size |
數值 |
(可選)為固定集合指定一個最大值(以位元組計)。 如果 capped 為 true,也需要指定該欄位。 |
| max |
數值 |
(可選)指定固定集合中包含文檔的最大數 |
例如:在exam表中建立colle1集合:
> use examswitched to db exam> db.createCollection("colle1"){ "ok" : 1 }> show collections #查看當前資料庫的集合colle1system.indexes
建立固定集合 mycol,整個集合空間大小 6142800 KB, 文檔最大個數為 10000 個。
> db.createCollection("mycol", { capped : true, autoIndexId : true, size : 6142800, max : 10000 } ){ "ok" : 1 }>
2.在 MongoDB 中,你不需要建立集合。當你插入一些文檔時,MongoDB 會自動建立集合。
> show collectionscolle1system.indexes> db.exam.insert({"name111" : "菜鳥教程"})WriteResult({ "nInserted" : 1 })> show collectionscolle1examsystem.indexes MongoDB 刪除集合
文法格式:
db.collection.drop()
傳回值
如果成功刪除選定集合,則 drop() 方法返回 true,否則返回 false。
例如:查看所有的集合并刪除其中一個集合
> show collectionscolle1examsystem.indexes> show tablescolle1examsystem.indexes> db.colle1.drop()true> show tablesexamsystem.indexes>
查看當前資料的集合可以用show collections或者show tables
mongodb的集合操作