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快速入門(mén)筆記(二)之MongoDB的概念及簡(jiǎn)單操作的相關(guān)知識(shí),希望對(duì)大家有所幫助!
您可能感興趣的文章:- java操作mongodb基礎(chǔ)(查詢 排序 輸出list)
- java操作mongodb實(shí)現(xiàn)CURD功能實(shí)例
- java查詢mongodb中的objectid示例
- MongoDB快速入門(mén)筆記(六)之MongoDB刪除文檔操作
- MongoDB快速入門(mén)筆記(六)之MongoDB的文檔修改操作
- MongoDB快速入門(mén)筆記(四)之MongoDB查詢文檔操作實(shí)例代碼
- MongoDB快速入門(mén)筆記(三)之MongoDB插入文檔操作
- MongoDB快速入門(mén)筆記(一)之windows下安裝MongoDB方法
- MongoDB快速入門(mén)筆記(七)MongoDB的用戶管理操作
- MongoDB快速入門(mén)筆記(八)之MongoDB的java驅(qū)動(dòng)操作代碼講解