我爱编程

MongoDB基本语法(1)

2018-06-21  本文已影响0人  wayne1125

一、创建数据库

启动mongo后输入

> use test     //切换到wayne数据库或创建wayne(创建时必须insert数据才能创建成功)
switched to db test
>db.test.insert({"name","test","age":25}))    //创建test成功
> db    //查看当前数据库
test
> db.test.insert({"name":"wayne"})
WriteResult({ "nInserted" : 1 })
> show dbs
local   0.078GB
runoob  0.078GB
test    0.078GB
> 

创建test数据库之后show dbs没有test数据库,必须insert数据后才会在show dbs 显示

二、删除数据库

>use test    //必须切换到某个指定数据库才能成功删除
switched to db test
> db.dropDatabase()
{ "dropped" : "test", "ok" : 1 }
> show dbs
local   0.078GB
runoob  0.078GB
> 

三、创建集合

> use test
switched to db test
> db.createCollection("testCollection")
{ "ok" : 1 }
> show collections
testCollection
system.indexes
>
上一篇 下一篇

猜你喜欢

热点阅读