安裝方式
讓客戶滿意是我們工作的目標,不斷超越客戶的期望值來自于我們對這個行業(yè)的熱愛。我們立志把好的技術通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領域值得信任、有價值的長期合作伙伴,公司提供的服務項目有:申請域名、網(wǎng)頁空間、營銷軟件、網(wǎng)站建設、東城網(wǎng)站維護、網(wǎng)站推廣。
采用apt-get install MongoDB命令直接進行,采用源碼包安裝也可以
hadoop@dblab:/$ sudo apt-get update
hadoop@dblab:/$ sudo apt-get install -y mongodb-org
hadoop@dblab:/$ mongo -version
MongoDB shell version: 3.2.22
hadoop@dblab:/$ sudo service mongodb start #啟動MongoDB
hadoop@dblab:/$ mongo? #進入MongoDB Shell模式
> use school? ?#切換到shcool數(shù)據(jù)庫,使用時會自動創(chuàng)建
switched to db school
> db.createCollection('teacher')? ? #創(chuàng)建集合
{ "ok" : 1 }
> show dbs? ?#顯示數(shù)據(jù)庫列表
local? 0.000GB
school? 0.000GB
> db.student.insert({_id:1,sname:'zhangsan',sage:20})? ?#插入數(shù)據(jù)
WriteResult({ "nInserted" : 1 })
> db.student.insert({_id:2,sname:'lisi',sage:22})? ?#插入數(shù)據(jù)
WriteResult({ "nMatched" : 0, "nUpserted" : 1, "nModified" : 0, "_id" : 2 })
> use school
switched to db school
> show collections? ?#顯示當前數(shù)據(jù)庫的集合
student
teacher
#查找數(shù)據(jù)
> db.student.find()? ?#查找所有記錄
{ "_id" : 1, "sname" : "lisi", "sage" : 22 }
{ "_id" : 2, "sname" : "lisi", "sage" : 22 }
> db.student.remove({_id: 2})? ? #刪除數(shù)據(jù)
WriteResult({ "nRemoved" : 1 })
> db.student.find()
{ "_id" : 1, "sname" : "lisi", "sage" : 22 }
> db.student.insert({_id:2,sname:'zhangsan',sage:25})
WriteResult({ "nInserted" : 1 })
> db.student.find()
{ "_id" : 1, "sname" : "lisi", "sage" : 22 }
{ "_id" : 2, "sname" : "zhangsan", "sage" : 25 }
>?
#修改數(shù)據(jù)
> db.student.update({_id:2},{$set:{sage:88}},false,true)
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.student.find().pretty()
{ "_id" : 1, "sname" : "lisi", "sage" : 22 }
{ "_id" : 2, "sname" : "zhangsan", "sage" : 88 }
#刪除數(shù)據(jù)
> db.student.remove({sname:'lisi'})
WriteResult({ "nRemoved" : 1 })
#刪除集合
> db.student.drop()
> show collections
teacher
> exit? #退出MongoDB Shell模式
bye