Created
November 19, 2014 07:01
-
-
Save HaraShun/213d169f872b81d63223 to your computer and use it in GitHub Desktop.
『初心者向けMongoDBのキホン!』より、サンプルコマンド
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 『初心者向けMongoDBのキホン!』より、サンプルコマンド | |
| http://www.slideshare.net/tetsutarowatanabe/mongo-db-32210761 | |
| ※Rubyとの接続のサンプルもあり | |
| ■コマンドメモ | |
| # インストール | |
| # ダウンロードページ http://www.mongodb.org/downloads | |
| wget http://fastdl.mongodb.org/linux/mongodb-linux-i686- 2.4.9.tgz | |
| tar zxvf mongodb-linux-i686-2.4.9.tgz | |
| # 起動 cd mongodb-linux-i686-2.4.9 | |
| mkdir data | |
| ./bin/mongod --dbpath=data --nojournal | |
| ps -ef | grep mongo | |
| http://192.168.80.130:28017/ | |
| # MongoDBへ接続 | |
| ./bin/mongo | |
| # 基本的なCRUD | |
| use mydb | |
| db.mycol.insert({"key1":"value1"}) | |
| db.mycol.insert({"key2":"value2"}) | |
| db.mycol.find() | |
| db.mycol.find({"key1":"value1"}) | |
| db.mycol.update({"key1":"value1"},{"key1":"value-hoge"}) | |
| db.mycol.remove({"key1":"value1"}) | |
| db.mycol.remove() | |
| # 少し実践的なデータで試してみる | |
| db.profile.insert( | |
| { | |
| "name" : "watanabe", | |
| "skill" : ["MongoDB","KVM","ruby"], | |
| "job":{ | |
| "before" : "Online Trade System", | |
| "now" : "Open Source" | |
| }, | |
| "editor":"emacs" | |
| } | |
| ) | |
| db.profile.insert( | |
| { | |
| "name" : "ogasawara", | |
| "skill" : ["MongoDB","LibreOffice","Printing"], | |
| "editor":"vim" | |
| } | |
| ) | |
| db.profile.insert( | |
| kubota = { | |
| "name" : "kubota", | |
| "skill" : ["MongoDB","MySQL","PostgreSQL","ruby","c++","java","Web"], | |
| "editor":"emacs", "keybord":"kinesis" | |
| } | |
| ) | |
| db.profile.find({"skill":"MongoDB"},{"name":1}) | |
| db.profile.find({"skill":"KVM"},{"name":1}) | |
| watanabe = db.profile.findOne({"name":"watanabe"}) | |
| watanabe["job"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment