1,刪除數據庫: db.dropDatabase()數據庫
> use Chenshi switched to db Chenshi > db Chenshi > show dbs local0.078125GB > db.computer.insert({"name":"lisi"}) > show dbs Chenshi0.203125GB local0.078125GB > db.dropDatabase() {"dropped":"Chenshi","ok":1} > show dbs local0.078125GB
> db.createCollection("shiyanlou") {"ok":1} > show collections shiyanlou system.indexes > db.createCollection("shiyanlou2",{capped:1, autoIndexID:1, size:6142800, m ax :10000}) {"ok":1}
capped:類型爲Boolean,若是爲ture則建立一個固定大小的集合,當其條目達到最大時能夠自動覆蓋之前的條目。在設置其爲ture時也要指定參數大小;
autoIndexID:類型爲Boolean,默認爲false,若是設置爲ture,則會在_id field.s上自動建立索引;
size:若是capped爲ture須要指定,指定參數的最大值,單位爲byte;
max:指定最大的文檔數。在mogodb中也能夠不用建立集合,由於在建立文檔的時候也會自動的建立集合
> use shiyanlou switched to db shiyanlou > show collections shiyanlou2 system.indexes > db.shiyanlou2.drop() true > db.shiyanlou.drop() false
> userdoc1=({"user_id":1,"name":"cloud","state":"active","actor":"user" ,"email":"test@qq.com","VM_num":2,"time":[{"date":"2014-05-56","hour": "5:34 PM"}]}) { "user_id":1, "name":"cloud", "state":"active", "actor":"user", "email":"test@qq.com", "VM_num":2, "time":[ { "date":"2014-05-56", "hour":"5:34 PM" } ] } > use Chenshi switched to db Chenshi > db.shiyanlou.insert(userdoc1) > db.shiyanlou.insert(userdoc2) MonMay1819:36:25.849ReferenceError: userdoc2 is not defined > db.shiyanlou.insert(userdoc1)
> db.shiyanlou.remove({"name":"Bob"})