歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> MongoDB基本命令

MongoDB基本命令

日期:2017/2/28 15:57:53   编辑:Linux教程

show dbs; 顯示db名稱及占用情況

show collections; 顯示db下面的collection的名稱

use xxdb; 使用具體的db

db.dropDatabase(); 刪除指定數據庫,必須現use xxdb再使用

db.xxcollection.drop(); 刪除集合

db.xxcollection.find(); 查看collection中的記錄

db.xxcollection.remove({_id:xxx}); 刪除記錄

mongoexport --port 10240 -d xxdb -c xxcollection -o xxcollection.dat; 導出數據, 數據格式為json

mongoexport --port 10240 -d xxdb -c xxcollection -csv -f uid,username,age -o xxcollection.dat; 導出數據,數據格式為csv(逗號分割值)

mongoimport --port 10240 -d xxdb -c xxcollection -o xxcollection.dat ; 導入數據,數據格式為json

mongoimport --port 10240 -d xxdb -c xxcollection --type csv --headerline -file user_csv.dat ; 導入數據,數據格式為csv,不導入第一行(該行為列名)

mongodump -d xxdb -o xxdbdir; 數據庫備份到xxdbdir目錄下

mongorestore -d xxdb xxdbdir/*; 恢復數據到指定庫下

測試失敗,許重新測試

mongod -f file.cnf --auth --fork; mongod啟動時指定認證

mongo --port xxx -u username -p; 指定用戶名密碼登錄

Copyright © Linux教程網 All Rights Reserved