こんな感じでエラーがでて起動しない。試したのはUbuntu12.04(32bit)。Ruby×Mongoid×MongoDB: 導入から動作確認まで (Ubuntu) – たいぷらいたーざっき。(2012-01-31)さんの記事を元に、開発元からaptでインストール。V2.2.3が入った。
$ mongo MongoDB shell version: 2.2.3 connecting to: test Wed Feb 6 17:54:23 Error: couldn't connect to server 127.0.0.1:27017 src/mongo/shell/mongo.js:91 exception: connect failed
rootで起動してもダメ。
はて…?
検索すると
1.ポート27017番が塞がっていないか→テスト用なのでファイアウォール起動していなかったので、ポート関係ではない
2./var/lib以下を777にすればもしかしたら動くかも→ちょっと恐ろしいし本番ではできないので試してない
mongoサーバが起動していないんじゃ…?
mongodb使ったことないけど、頑張って調査(`・ω・´)
$ sudo service mongodb start mongodb start/running, process 2025 $ ps aux|grep 2025 hogehoge 2030 0.0 0.0 5340 840 pts/0 S+ 17:57 0:00 grep --color=auto 2025
startと言っているのにプロセスにいないような… 起動に失敗しているんじゃないだろうか?
結局、開発版のじゃなくてUbuntu12.04標準のmongodbをaptで入れるとOKだった。v2.0.4
$ sudo apt-get install mongodb $ 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 >
最新版だからまだエラーがあるのかな。とりあえずv2.0.4使うことにする(・∀・)