mongoDB数据库文件路径和数据操作
生活随笔
收集整理的這篇文章主要介紹了
mongoDB数据库文件路径和数据操作
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1、查看MongoDB在電腦上的安裝路徑
which mongod
2、默認mongodb 數據文件是放到根目錄 data/db 文件夾下,如果沒有這個文件,需要自行創建
mkdir -p /data/db
3、或者,也可以在每次啟動時指定數據庫路徑:
mongod --dbpath /usr/local/db
4、插入數據:
db.student.insert({"name":"xiaoming"});
5、查詢數據的方法:
查找數據,用find。find中沒有參數,那么將列出這個集合的所有文檔:
db.restaurants.find()
精確匹配:
db.student.find({"score.shuxue":70});
多個條件:
db.student.find({"score.shuxue":70 , "age":12})
大于條件:
db.student.find({"score.yuwen":{$gt:50}});
或者。尋找所有年齡是9歲,或者11歲的學生
db.student.find({$or:[{"age":9},{"age":11}]});
查找完畢之后,打點調用sort,表示升降排序。
db.restaurants.find().sort( { "borough": 1, "address.zipcode": 1 } )
6、修改數據:
修改里面還有查詢條件。要該誰,要告訴mongo。
db.student.update({"name":"小明"},{$set:{"age":16}});
查找數學成績是70,把年齡更改為33歲:
db.student.update({"score.shuxue":70},{$set:{"age":33}});
更改所有匹配項目:"
By default, the update() method updates a single document. To update multiple documents, use the multi option in the update() method.
db.student.update({"sex":"男"},{$set:{"age":33}},{multi: true});
完整替換,不出現$set關鍵字了:
db.student.update({"name":"小明"},{"name":"大明","age":16});
7、刪除數據
db.restaurants.remove( { "borough": "Manhattan" } )
By default, the remove() method removes all documents that match the remove condition. Use the justOne option to limit the remove operation to only one of the matching documents.
db.restaurants.remove( { "borough": "Queens" }, { justOne: true } )
總結
以上是生活随笔為你收集整理的mongoDB数据库文件路径和数据操作的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: oracle中导入.dmp文件时出现IM
- 下一篇: MySQL连接处理方式及最佳并发连接数设