MongoDB中的collections就是一系列 BSON documents的集合,至關於關係數據庫中的表。shell
collection將會在第一次往裏面插入documents時建立數據庫
> show dbs;
app
admin (empty)
spa
foo 0.0625GB
it
fucker 0.0625GB
io
local (empty)
test
test 0.0625GB
方法
> use fucker;
命名
switched to db fucker
數據
> show collections;
fucker
system.indexes
users
> db.test.insert({"id" : 1 });
> show collections;
fucker
system.indexes
test
users
collection名最大長度爲128個字符,建議不要超80/90個字符
能夠使用以下命令來建立collection(通常用於建立Capped collections)
> show collections;
fucker
system.indexes
test
users
> //mongo shell
> db.createCollection("mycoll",{capped:true, size:100000}) //size is in bytes
{ "ok" : 1 }
> show collections;
fucker
mycoll
system.indexes
test
users
> show collections;
fucker
mycoll
system.indexes
test
users
> db.runCommand( {create:"mycoll_1", capped:true, size:100000} )
{ "ok" : 1 }
> show collections;
fucker
mycoll
mycoll_1
system.indexes
test
users
> show collections;
fucker
mycoll
mycoll_1
system.indexes
test
users
> db.mycoll.renameCollection("Yourcoll");
{ "ok" : 1 }
> show collections;
Yourcoll
fucker
mycoll_1
system.indexes
test
users
> show collections;
Yourcoll
fucker
mycoll_1
system.indexes
test
users
> use admin;
switched to db admin
> db.runCommand( { renameCollection: "fucker.Yourcoll", to: "fucker.Hiscoll"} );
{ "ok" : 1 }
> use fucker;
switched to db fucker
> show collections;
Hiscoll
fucker
mycoll_1
system.indexes
test
users