創(chuàng)建集合
db.createCollection(name, options)
? ? name: 集合名稱落追,String類型喇颁。
? ? options: 指定有關(guān)內(nèi)存大小及索引的選項逮诲,文檔類型宜肉。
? ? options參數(shù)詳情:
? ??????capped:true則啟用封閉的集合。上限集合是固定大小的集合侦啸,它在達到其最大大小時自動覆蓋其最舊的條目槽唾。 如果指定true,則還需要指定size參數(shù)光涂。
????????size:為固定集合指定一個最大值(以字節(jié)計)庞萍。
? ??????autoIndexId:true則自動在 _id 字段創(chuàng)建索引。默認為 false忘闻。
? ??????max:指定上限集合中允許的最大文檔數(shù)钝计。
創(chuàng)建集合例子:
db.createCollection("mycol")
創(chuàng)建固定集合 mycol,整個集合空間大小 6142800 KB, 文檔最大個數(shù)為 10000 個齐佳。
db.createCollection(
????"mycol",
?????{
????????capped : true,
????????autoIndexId : true,
????????size : 6142800,
????????max : 10000? ?
????}
)
在 MongoDB 中私恬,當(dāng)插入一些文檔時,MongoDB 會自動創(chuàng)建集合炼吴。
db.mycol.insert({"name" : "mongodb_doc"})
? ? 其他相關(guān)命令:
? ? ? ? 查看創(chuàng)建的集合:show collections
? ? ? ? 刪除集合:db.collection_name.drop()