mongodb创建数据库可以直接用use
先看看有哪些db:
> show dbs
admin (empty)
local 0.078GB
mydb 0.078GB
test (empty)
>
再新建一个数据库mytestdb:
> use mytestdb
switched to db mytestdb
>
如果什么都不操作离开的话,这个库就会被系统删除:
> show dbs
admin (empty)
local 0.078GB
mydb 0.078GB
test (empty)
>
如果插入一条语句,就可以保存下来:
在mydb库中的user表中插入一条记录
> db.user.insert({name:'jack'})
WriteResult({ "nInserted" : 1 })
查看有哪些db库
> show dbs
admin (empty)
local 0.078GB
mydb 0.078GB
mytestdb 0.078GB
test (empty)
切换到mytestdb库
> use mytestdb
switched to db mytestdb
查看mytestdb库中的所有表
> show collections
system.indexes
user
查看user表内容:
> db.user.find()
{ "_id" : ObjectId("54deb3fcf0d67ffc85508f9a"), "name" : "jack" }
>
表的删除:
删除user表
> db.user.drop();
true
检查mytest库中的表,user已经不存在了
> show collections
system.indexes
>
删除mytestdb库
> use mytestdb
switched to db mytestdb
> db.dropDatabase()
{ "dropped" : "mytestdb", "ok" : 1 }
> show dbs
admin (empty)
local 0.078GB
mydb 0.078GB
test (empty)
数据库mytestdb已经被删除
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29806344/viewspace-1438399/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/29806344/viewspace-1438399/