on Windows。
於 http://www.mongodb.org/downloads 下載適合版本,解壓縮至 C:\ 並更名為 mongodb,
cd \mongodb
C:\mongodb>mkdir data
C:\mongodb>mkdir log

編輯設定檔案 (C:\mongodb\bin\mongo.conf)
# mongo.conf
rest = true
nojournal = true
logpath=C:\mongodb\log\mongo.log
logappend=true
port = 27017
dbpath=C:\mongodb\data


cd \mongodb\bin
C:\mongodb\bin>mongod -f C:\mongodb\bin\mongo.conf --auth --install
all output going to: C:\mongodb\log\mongo.log

註冊及啟動服務
C:\mongodb\bin>net start MongoDB

Mongo DB 服務已經啟動成功。

移除服務
C:\mongodb\bin>net stop MongoDB
C:\mongodb\bin>mongod --remove

連接 MongoDB
C:\mongodb\bin>mongo.exe localhost:port/db

mongoexport 匯出 DB
mongoexport --db {資料庫名稱(flyfox)} --collection {collection名稱(MyBackEnd)} --out {路徑/json檔名} --journal

C:\mongodb\bin>mongoexport.exe --db flyfox --collection MyBackend --out D:\mybackup.json
connected to: 127.0.0.1
exported 123 records

mongoimport 匯入 DB
mongoimport -d {資料庫名稱(flyfox)} -c {collection名稱(MyBackEnd)} {路徑/json檔名}

C:\mongodb\bin>mongoimport.exe -d flyfox -c MyBackEnd C:\mongodb\data\MyBackEnd_201212280900.json

mongodump 匯出 DB
-h:host
-d:資料庫名稱
-o:備份檔存放路徑

C:\mongodb\bin>mongodump -h 127.0.0.1:27017 -d flyfox -o D:\mybackup
connected to: 127.0.0.1
Wed Mar 06 19:02:03 DATABASE: flyfox to D:/mybackup/flyfox
Wed Mar 06 19:02:03 flyfox.MyBackend to D:/mybackup/flyfox/MyBackend.bson
Wed Mar 06 19:02:03 323 objects
Wed Mar 06 19:02:03 Metadata for flyfox.MyBackend to D:/mybackup/flyfox/MyBa
ckend.metadata.json
Wed Mar 06 19:02:03 flyfox.system.users to D:/mybackup/flyfox/system.users.b
son
Wed Mar 06 19:02:03 1 objects
Wed Mar 06 19:02:03 Metadata for flyfox.system.users to D:/mybackup/flyfox/s
ystem.users.metadata.json


mongorestore 匯入 DB
-h:host
-d:資料庫名稱
--directoryperdb:備份檔存放路徑
--drop:還原資料庫前刪除目前資料

C:\mongodb\bin>mongorestore.exe -h 127.0.0.1:27017 -d flyfox --directoryperdb D:\mybackup\flyfox --drop
connected to: 127.0.0.1
Wed Mar 06 19:01:04 D:/mybackup/flyfox/MyBackend.bson
Wed Mar 06 19:01:04 going into namespace [flyfox.MyBackend]
Wed Mar 06 19:01:04 dropping
323 objects found
Wed Mar 06 19:01:04 Creating index: { key: { _id: 1 }, ns: "flyfox.MyBackend
", name: "_id_" }
Wed Mar 06 19:01:04 D:/mybackup/flyfox/system.users.bson
Wed Mar 06 19:01:04 going into namespace [flyfox.system.users]
1 objects found
Wed Mar 06 19:01:04 Creating index: { key: { _id: 1 }, ns: "flyfox.system.us
ers", name: "_id_" }


查詢資料
db.flyfox.find({'Date':'20130218',"User" : "flyfox"}).limit(50).explain();

匯出查詢資料
C:\mongodb\bin>mongoexport.exe -h 192.168.1.1:27017 -d flyfox -c MyUser -q "{'Date' : '20130208','User' :
'CUHHMFG'}" -o D:\CUHHMFG.json --journal

flyfox 發表在 痞客邦 PIXNET 留言(0) 人氣()