下載 MongoDB
在這個網址中提供各個不同版本的 MongoDB,因為現階段還在本機開發,所以我使用 Windows 的版本,方便測試。不過設定上對 Linux 來說也是大同小異的。
http://http://www.mongodb.org/downloads
http://http://www.mongodb.org/downloads
cd \mongodb mkdir data mkdir logs
# mongo.conf rest = true nojournal = true #where to log logpath=C:\MongoDB\logs\mongo.log logappend=true #fork = true port = 27017 dbpath=C:\MongoDB\data #master=true #auth = true #verbose = true replSet = your_replset
C:\MongoDB\bin>mongo MongoDB shell version: 2.0.4 connecting to: test > help db.help() help on db methods db.mycoll.help() help on collection methods rs.help() help on replica set methods help admin administrative help help connect connecting to a db help help keys key shortcuts help misc misc things to know help mr mapreduce show dbs show database names show collections show collections in current database show users show users in current database show profile show most recent system.profile entries with time >= 1ms show logs show the accessible logger names show log [name] prints out the last segment of log in memory, 'global' is default use <db_name> set current database db.foo.find() list objects in collection foo db.foo.find( { a : 1 } ) list objects in foo where a == 1 it result of the last line evaluated; use to further iterate DBQuery.shellBatchSize = x set default number of items to display on shell exit quit the mongo shell
C:\MongoDB\bin>mongo MongoDB shell version: 2.0.4 connecting to: test > rs.initiate(); { "info2" : "no configuration explicitly specified -- making one", "me" : "YOUR_COMPUTER_NAME", "info" : "Config now saved locally. Should come online in about a minute.", "ok" : 1 } PRIMARY>