日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

mongoDB数据库文件路径和数据操作

發布時間:2023/12/13 综合教程 46 生活家
生活随笔 收集整理的這篇文章主要介紹了 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数据库文件路径和数据操作的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。