安裝?mongodb? ?sudo?apt?install? mongodb
啟動(dòng)mongodb :? ?sudo?mongodb
虛擬硬盤不夠?
sudo?mongodb --smallfiles
后臺(tái)服務(wù)器啟動(dòng)方式
注意:必須是使用sudo apt?install? mongdb? 這種方式才有效
sudo?service mongodb?start
#####關(guān)閉#####
1.直接使用?ctrl +?c
2 可以通過登錄mongodb客戶端來關(guān)閉??
?use? admin??
?db.shutdownServer()
使用kill殺死進(jìn)程
?如果使用服務(wù)啟動(dòng)
sudo?server?mongodb?stop
###啟動(dòng)參數(shù)說明
--dbpath? 數(shù)據(jù)庫存儲(chǔ)路徑? 默認(rèn)/data/db
--port? 數(shù)據(jù)庫的端口?默認(rèn) 27017
--auth?啟動(dòng)認(rèn)證模式
--bind_ip?允許數(shù)據(jù)庫管理系統(tǒng)連接的ip地址
--config? 設(shè)置配置文件路徑?在配置文件中可以配置
遠(yuǎn)程連接//開啟mongodb服務(wù)器
mongo? --host? ? ?--port 27017
mongodb操作使用
###數(shù)據(jù)庫操作
show?database /dbs
###進(jìn)入數(shù)據(jù)庫數(shù)據(jù)庫列表
?use?數(shù)據(jù)庫名
####顯示當(dāng)前的數(shù)據(jù)庫
db
###創(chuàng)建數(shù)據(jù)庫
插入數(shù)據(jù)就是創(chuàng)建數(shù)據(jù)庫
###刪除數(shù)據(jù)庫
use?到數(shù)據(jù)庫中
db.dropDatabase()
####操作集合###
顯示集合?show?collections
###前提條件
先use?數(shù)據(jù)庫
然后創(chuàng)建集合
\\方式2
db.createCollection('集合名稱')
####刪除集合###
db.集合名.drop()
####重命名集合###
db.集合名.renameCollection('新集合名')
#####數(shù)據(jù)操作###
創(chuàng)建數(shù)據(jù)
?? ??? ?? ? //創(chuàng)建單條數(shù)據(jù)?
?? ??? ?? ? db.集合名insert({
?? ??? ?? ? "name":"mysql"
})
?? ??? ?? ? //多條數(shù)據(jù)插入
?? ??? ?? ? data = [
?? ?? ? {"name":"wang"},
?? ?? ? {"name":'abc}
]
db.集合名.insertMany(data)
更新數(shù)據(jù)?
db.集合名.update{ //更新條件{“name”:“wang”}淳蔼,//更新內(nèi)容? {"name":"fdfewf"}}?這個(gè)是整體更新?更新為一條數(shù)據(jù)
局部更新 update{//更新條件{“name”:“wang”}, //更新內(nèi)容? $set:{"name":"fdfewf"}}}?只更新一條滿足條件的數(shù)據(jù)
局部全局更新?update{//更新條件{“name”:“wang”}窃诉, //更新內(nèi)容? $set:{"name":"fdfewf"},{ multi:true}}}?局部更新所有滿足條件的數(shù)據(jù)?
保持?jǐn)?shù)據(jù)
刪除數(shù)據(jù)
批量刪除? db.stu.remove{//刪除條件{"name":"wang"}}
刪除一條?db.stu.remove(//刪除條件{"name":"wang"},{ justOne:true })
清空數(shù)據(jù)? db.stu.remove({})
查詢數(shù)據(jù)
默認(rèn)查詢條件是并的關(guān)系?如果查詢所有數(shù)據(jù)可以不傳遞如何參數(shù)
?? ??? ?? ? db.集合名.find(//查詢條件{"name":""大理, "age":16}).prepty()
####比較運(yùn)算符##
greater?than,greater?than?equal,??less?than冯乘,less?than?equal枷恕,not?equal
把單詞縮寫
$gt? $gte? $lt? ?$lte? $ne