読者です 読者をやめる 読者になる 読者になる

それマグで!

知識はカップより、マグでゆっくり頂きます。 takuya_1stのブログ

習慣に早くから配慮した者は、 おそらく人生の実りも大きい。

homebrew でmongdbをインストール

インストール

brew install mongodb

起動

 /usr/local/opt/mongodb/mongod  --config /usr/local/etc/mongod.conf

接続

mongo 

データベース一覧

> show dbs

データ挿入

> db.my_first.users.save({name:"takuya",uid:"takuya_1st”})

name : takuya  のレコード my_first コレクションの users コレクション内に追加する。

名前空間(コレクション)は自由に決められる。

データの取り出し

> db.my_first.users.find({name:"takuya"})
{ "_id" : ObjectId("52819c8aff7a562e487279b0"), "name" : "takuya", "uid" : "takuya_1st" } 

データベース切替

>use my_first_db

TIPS

mongoシェルはSpiderMonkeyシェルの拡張。へー

実際に試してみたのがこちら

takuya@air:~/Desktop$ /usr/local/opt/mongodb/mongod  --config /usr/local/etc/mongod.conf
Tue Nov 12 12:04:33.576 [initandlisten] MongoDB starting : pid=7055 port=27017 dbpath=/usr/local/var/mongodb 64-bit host=air.local
Tue Nov 12 12:04:33.576 [initandlisten] db version v2.4.7
Tue Nov 12 12:04:33.576 [initandlisten] git version: nogitversion
Tue Nov 12 12:04:33.576 [initandlisten] build info: Darwin air 13.0.0 Darwin Kernel Version 13.0.0: Thu Sep 19 22:22:27 PDT 2013; root:xnu-2422.1.72~6/RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_49
Tue Nov 12 12:04:33.576 [initandlisten] allocator: tcmalloc
Tue Nov 12 12:04:33.576 [initandlisten] options: { bind_ip: "127.0.0.1", config: "/usr/local/etc/mongod.conf", dbpath: "/usr/local/var/mongodb" }
Tue Nov 12 12:04:33.578 [initandlisten] journal dir=/usr/local/var/mongodb/journal
Tue Nov 12 12:04:33.578 [initandlisten] recover : no journal files present, no recovery needed
Tue Nov 12 12:04:33.612 [FileAllocator] allocating new datafile /usr/local/var/mongodb/local.ns, filling with zeroes...
Tue Nov 12 12:04:33.612 [FileAllocator] creating directory /usr/local/var/mongodb/_tmp
Tue Nov 12 12:04:33.783 [FileAllocator] done allocating datafile /usr/local/var/mongodb/local.ns, size: 16MB,  took 0.17 secs
Tue Nov 12 12:04:33.819 [FileAllocator] allocating new datafile /usr/local/var/mongodb/local.0, filling with zeroes...
Tue Nov 12 12:04:34.092 [FileAllocator] done allocating datafile /usr/local/var/mongodb/local.0, size: 64MB,  took 0.272 secs
Tue Nov 12 12:04:34.132 [initandlisten] command local.$cmd command: { create: "startup_log", size: 10485760, capped: true } ntoreturn:1 keyUpdates:0  reslen:37 520ms
Tue Nov 12 12:04:34.132 [websvr] admin web console waiting for connections on port 28017
Tue Nov 12 12:04:34.132 [initandlisten] waiting for connections on port 27017

参考資料

http://nigohiroki.hatenablog.com/entry/2013/01/05/234631 http://qiita.com/yuiseki/items/1c656d6bab0307e1510c

広告を非表示にする