MongoDB是面向集合的文檔式數(shù)據(jù)庫,不像關(guān)系數(shù)據(jù)庫那樣,有表,列、行,mongoDB數(shù)據(jù)庫則是由一系列的文檔組成。下面給大家介紹MongoDB的概念及簡單操作.
1、以下列舉普通的關(guān)系型數(shù)據(jù)庫和MongoDB數(shù)據(jù)庫簡單概念上的區(qū)別:
![](http://img.jbzj.com/file_images/article/201606/201661113710307.png?201651113733)
2、MongoDB的簡單操作
(1)啟動MongoDB數(shù)據(jù)庫之后,使用命令mongo,顯示如下,默認連接到test數(shù)據(jù)庫。
MongoDB shell version: 3.2.6
connecting to: test
使用命令show dbs,可以查看所有的數(shù)據(jù)庫,可以看見只有一個local數(shù)據(jù),其實test數(shù)據(jù)庫并不存在,只有再建集合并往集合插入數(shù)據(jù)時才會真正的建表。
常用命令:
show dbs 顯示所有的數(shù)據(jù)庫
use 數(shù)據(jù)庫名 切換到某一個數(shù)據(jù)中
show collections 顯示當前數(shù)據(jù)庫中所有的集合
db.集合名.find() 查詢當前數(shù)據(jù)庫中某一個集合下所有的數(shù)據(jù)
db.集合名.insert({"鍵": "值", "鍵": "值" ...}) 給當前數(shù)據(jù)庫中某一個集合添加數(shù)據(jù)
db.集合名.drop() 刪除某一個集合
db.dropDatabase() 刪除當前數(shù)據(jù)庫
現(xiàn)在我們用以上命令做一個簡單的例子:重新建立一個數(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ù)時,會自動添加一個主鍵“_id”
以上內(nèi)容是小編給大家介紹的MongoDB快速入門筆記(二)之MongoDB的概念及簡單操作的相關(guān)知識,希望對大家有所幫助!
您可能感興趣的文章:- java操作mongodb基礎(chǔ)(查詢 排序 輸出list)
- java操作mongodb實現(xiàn)CURD功能實例
- java查詢mongodb中的objectid示例
- MongoDB快速入門筆記(六)之MongoDB刪除文檔操作
- MongoDB快速入門筆記(六)之MongoDB的文檔修改操作
- MongoDB快速入門筆記(四)之MongoDB查詢文檔操作實例代碼
- MongoDB快速入門筆記(三)之MongoDB插入文檔操作
- MongoDB快速入門筆記(一)之windows下安裝MongoDB方法
- MongoDB快速入門筆記(七)MongoDB的用戶管理操作
- MongoDB快速入門筆記(八)之MongoDB的java驅(qū)動操作代碼講解