基本语法
MongoDB 创建数据库的语法格式如下:
use DATABASE_NAME
如果数据库不存在,则创建数据库,否则切换到指定数据库。
实例
以下实例我们创建了数据库 coderschool:
> use coderschoolswitched to db coderschool> dbcoderschool>
如果你想查看所有数据库,可以使用 show dbs 命令:
> show dbslocal 0.078GBtest 0.078GB>
可以看到,我们刚创建的数据库 coderschool 并不在数据库的列表中, 要显示它,我们需要向 coderschool 数据库插入一些数据。
实例:> db.runoob.insert({"name":"技术拉近你我"})WriteResult({ "nInserted" : 1 })> show dbscoderschool 0.078GBlocal 0.078GBtest 0.078GB>
操作过程图:
MongoDB 中默认的数据库为 test,如果你没有创建新的数据库,集合将存放在 test 数据库中。
转载自,原文地址: