mongodb 建立資料庫的語法格式如下:
use database_name如果資料庫不存在,則建立資料庫,否則切換到指定資料庫。
以下例項我們建立了資料庫 runoob:
use runoob如果你想檢視所有資料庫,可以使用 show dbs 命令:switched to db runoob
dbrunoob
show dbs可以看到,我們剛建立的資料庫 runoob 並不在資料庫的列表中, 要顯示它,我們需要向 runoob 資料庫插入一些資料。admin 0.000gb
config 0.000gb
local 0.000gb
db.runoob.insert()mongodb 中預設的資料庫為 test,如果你沒有建立新的資料庫,集合將存放在 test 資料庫中。writeresult()
show dbs
admin 0.000gb
config 0.000gb
local 0.000gb
runoob 0.000gb
注意:在 mongodb 中,集合只有在內容插入後才會建立! 就是說,建立集合(資料表)後要再插入乙個文件(記錄),集合才會真正建立。
MongoDB 建立資料庫
mongodb 建立資料庫的語法格式如下 use database name如果資料庫不存在,則建立資料庫,否則切換到指定資料庫。以下例項我們建立了資料庫 runoob use runoob switched to db runoob db runoob 如果你想檢視所有資料庫,可以使用 show ...
MongoDB 建立資料庫
mongodb 建立資料庫的語法格式如下 use database name如果資料庫不存在,則建立資料庫,否則切換到指定資料庫。以下例項我們建立了資料庫 runoob userunoob switched to db runoob dbrunoob 如果你想檢視所有資料庫,可以使用 show db...
MongoDB 建立資料庫
mongodb 建立資料庫的語法格式如下 use database name如果資料庫不存在,則建立資料庫,否則切換到指定資料庫。以下例項我們建立了資料庫 runoob userunoob switched to db runoob dbrunoob 如果你想檢視所有資料庫,可以使用show dbs...