新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)MongoDB教程:MongoDB 創(chuàng)建數(shù)據(jù)庫
MongoDB 創(chuàng)建數(shù)據(jù)庫
語法
MongoDB 創(chuàng)建數(shù)據(jù)庫的語法格式如下:

use DATABASE_NAME
如果數(shù)據(jù)庫不存在,則創(chuàng)建數(shù)據(jù)庫,否則切換到指定數(shù)據(jù)庫。
實例
以下實例我們創(chuàng)建了數(shù)據(jù)庫 runoob:
> use runoob switched to db runoob > db runoob >
如果你想查看所有數(shù)據(jù)庫,可以使用 show dbs 命令:
> show dbs admin 0.000GB config 0.000GB local 0.000GB >
可以看到,我們剛創(chuàng)建的數(shù)據(jù)庫 runoob 并不在數(shù)據(jù)庫的列表中, 要顯示它,我們需要向 runoob 數(shù)據(jù)庫插入一些數(shù)據(jù)。
> db.runoob.insertOne({"name":"菜鳥教程"})
WriteResult({ "nInserted" : 1 })
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
runoob 0.000GB
MongoDB 中默認的數(shù)據(jù)庫為 test,如果你沒有創(chuàng)建新的數(shù)據(jù)庫,集合將存放在 test 數(shù)據(jù)庫中。
注意: 在 MongoDB 中,集合只有在內容插入后才會創(chuàng)建! 就是說,創(chuàng)建集合(數(shù)據(jù)表)后要再插入一個文檔(記錄),集合才會真正創(chuàng)建。
分享題目:創(chuàng)新互聯(lián)MongoDB教程:MongoDB 創(chuàng)建數(shù)據(jù)庫
當前地址:http://m.5511xx.com/article/dpciije.html


咨詢
建站咨詢
