1. 安裝
sudo apt-get update
sudo apt-get install mongodb
2. 進入MongoDB
#進入 mongo #選擇database use your_database
3. 為database新增使用者
#選擇database
use your_database
#新增使用者
db.addUser('account','password')
#登入帳號
db.auth('account', 'password')
4. 新增table
db.table_name.insert(
{
"_id" : ObjectId("570f4c356709f6482b712d58"),
"username" : "tom",
"password" : "asdf34#$FGDfgdfgfd45gfdf65s1dfsf3",
"email" : "tom@gmail.com"
}
)
5. 刪除Database&Collection
刪除Database
use your_database db.dropDatabase()
刪除Collection
use your_database db.your_collection.drop()
6. 備份Database
Export Database
mongodump -d your_database -o "export檔案位置"
Import Database
mongorestore -d"database_name" "import檔案位置"
6. 備份Collection
Export Collection json file
mongoexport --db your_database --collection collection_name --out collection.json
Import Collection json file
mongoimport --db your_database --collection collection_name --jsonArray collection.json
文章標籤
全站熱搜
