--- title: Mongodb command tags: Mongodb description: Mongodb comman record --- # Mongodb 使用 command 紀錄 ## mongodn installation ``` $ apt-get install mongodb ``` --- ## start monogdb service ``` $ service mongodb start ``` --- ## Enter mongodb 進入mongodb的shell ``` $ mongo ``` --- ## create database 在mongodb的資料表建立database ``` $ use AI_ENGINE ```` --- ## create collection 在mongodb的資料表建立collection ``` $ db.createCollection("user_profile") ``` --- ## show collections 顯示所有已建立的collections ``` $ show collections ``` --- ## insert document data 在collections裡插入一筆數據 ``` $ db.user_profile.insert({"account": "shaung08", "password":"456789"}) ``` --- ## find document data 尋找collections裡的所有documnet ``` $ db.user_profile.find() ``` --- ## update document data 更新document的指定數據 ``` $ db.user_profile.update( { "account": "30" },{ $set : { "username":"shaung08"} }) ``` --- ## delete document data 刪除document裡的指定數據 ``` $ db.user_profile.update({"account": "30"}, {$unset: {"account": "30"}}) ``` --- ## delete one document 刪除一筆document ``` $ db.user_config.deleteOne({"_id" : ObjectId("60efa74a20fb5161e9365d47")}) ``` --- ## delete all document correspond to {"model" : "yolov5s"} 刪除document裡與{"model" : "yolov5s"}相符的資料 ``` $ db.user_config.deleteMany({"model" : "yolov5s"}) ``` --- ## Thank you! :dash: You can find me on - GitHub: https://github.com/shaung08 - Email: a2369875@gmail.com