MongoDB是面向集合的文檔式數(shù)據(jù)庫(kù),不像關(guān)系數(shù)據(jù)庫(kù)那樣,有表,列、行,mongoDB數(shù)據(jù)庫(kù)則是由一系列的文檔組成。下面給大家介紹MongoDB的概念及簡(jiǎn)單操作.
1、以下列舉普通的關(guān)系型數(shù)據(jù)庫(kù)和MongoDB數(shù)據(jù)庫(kù)簡(jiǎn)單概念上的區(qū)別:
2、MongoDB的簡(jiǎn)單操作
(1)啟動(dòng)MongoDB數(shù)據(jù)庫(kù)之后,使用命令mongo,顯示如下,默認(rèn)連接到test數(shù)據(jù)庫(kù)。
MongoDB shell version: 3.2.6
connecting to: test
使用命令show dbs,可以查看所有的數(shù)據(jù)庫(kù),可以看見(jiàn)只有一個(gè)local數(shù)據(jù),其實(shí)test數(shù)據(jù)庫(kù)并不存在,只有再建集合并往集合插入數(shù)據(jù)時(shí)才會(huì)真正的建表。
常用命令:
show dbs 顯示所有的數(shù)據(jù)庫(kù)
use 數(shù)據(jù)庫(kù)名 切換到某一個(gè)數(shù)據(jù)中
show collections 顯示當(dāng)前數(shù)據(jù)庫(kù)中所有的集合
db.集合名.find() 查詢當(dāng)前數(shù)據(jù)庫(kù)中某一個(gè)集合下所有的數(shù)據(jù)
db.集合名.insert({"鍵": "值", "鍵": "值" ...}) 給當(dāng)前數(shù)據(jù)庫(kù)中某一個(gè)集合添加數(shù)據(jù)
db.集合名.drop() 刪除某一個(gè)集合
db.dropDatabase() 刪除當(dāng)前數(shù)據(jù)庫(kù)
現(xiàn)在我們用以上命令做一個(gè)簡(jiǎn)單的例子:重新建立一個(gè)數(shù)據(jù)zyhtest,并在zyhtest中新建集合student,并往student中插入數(shù)據(jù)。
> use zyhtest switched to db zyhtest > db.student.insert({"name": "zhangsan", "age": 28}) WriteResult({ "nInserted" : 1 }) > show dbs local 0.000GB zyhtest 0.000GB > show collections student > db.student.find() { "_id" : ObjectId("5745b8a08dfa492b66e7d397"), "name" : "zhangsan", "age" : 28 } > db.student.drop() true > show dbs local 0.000GB > db.student.insert({"name": "zhangsan", "age": 28}) WriteResult({ "nInserted" : 1 }) > show dbs local 0.000GB zyhtest 0.000GB > show collections student > db.dropDatabase() { "dropped" : "zyhtest", "ok" : 1 } > show dbs local 0.000GB
插入數(shù)據(jù)時(shí),會(huì)自動(dòng)添加一個(gè)主鍵“_id”
以上內(nèi)容是小編給大家介紹的MongoDB快速入門筆記(二)之MongoDB的概念及簡(jiǎn)單操作的相關(guān)知識(shí),希望對(duì)大家有所幫助!
標(biāo)簽:大理 丹東 吉安 昭通 鶴崗 本溪 邯鄲 景德鎮(zhèn)
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《MongoDB快速入門筆記(二)之MongoDB的概念及簡(jiǎn)單操作》,本文關(guān)鍵詞 MongoDB,快速,入門,筆記,二,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。