mconnor (9) [Avatar] Offline
i'm stuck trying to run the mongo shell (chp. 8.3.3)

i have the node app.js server running. But when i open a new terminal window and type:

i get.
.... Error: couldn't connect to server at src/mongo/shell/mongo.js:145
exception: connect failed

and when i type: mongo --host localhost --port 3000

i get:

MongoDB shell version: 2.4.8
connecting to: localhost:3000/test
Thu Jan 9 12:43:16.052 DBClientCursor::init call() failed
Thu Jan 9 12:43:16.055 Error: DBClientBase::findN: transport error: localhost:3000 ns: admin.$cmd query: { whatsmyuri: 1 } at src/mongo/shell/mongo.js:147
exception: connect failed
michael.mikowski (247) [Avatar] Offline
Re: mongoDB
Certainly this is a MongoDB installation problem. If you are running Ubuntu-derived Linux, you can use the official repository to keep up to date with all dependencies. For me, this has always just worked. Let me know if this is your setup and I can probably help.

However, my experience on Mac was much more problematic, but that was over a year ago. If that is your rig, the best resource there is probably stack overflow.
seasoup (37) [Avatar] Offline
Re: mongoDB
Is mongo started on port 27017? If its not started, start it by typing


If it is started on a different port, use that port. The port 3000 you reference in the second command is the port for the SPA application, not the mongo server.
mconnor (9) [Avatar] Offline
Re: mongoDB
thanks for the responses. I am on a mac OX 10.9.1.

so i tried this

$ mongo -- port 27017

and got:

MongoDB shell version: 2.4.8
connecting to: port
Thu Jan 9 15:00:09.749 Error: couldn't connect to server at src/mongo/shell/mongo.js:145
exception: connect failed

when i tried
mongod, i get
all output going to: /usr/local/var/log/mongodb/mongo.log

and then the cursor goes to blank line. So i'm not sure what is going on.

mongo --host localhost --port 27017
does not work either
MongoDB shell version: 2.4.8
connecting to: localhost:27017/test
Thu Jan 9 15:09:21.728 Error: couldn't connect to server localhost:27017 at src/mongo/shell/mongo.js:147
exception: connect failed
michael.mikowski (247) [Avatar] Offline
Re: mongoDB
Here is the baroque Mac instructions from over a year ago. Hopefully they are helpful, but they may be out of date. Once you are done with these steps, you should be able to type 'mongo' on the command line and get the shell without specifying the port.

This took many hours to resolve on the Mac and about one minute on Linux. Since I deploy on Linux and it works great for my development environment, I can't justify spending so much time configuring Mac boxes for development. I recognize this isn't true for everyone of course, but something to consider smilie

=== Mac MongoDB installation ===

1. Download and unpack the binary package from

2. Enter the following commands:

| ## replace the 2.2.0 with the downloaded version number
| sudo mv mongodb-osx-x86_64-2.2.0 /usr/local/mongodb
| sudo chown -R root /usr/local/mongodb
| sudo mkdir /usr/local/mongodb_data
| sudo mkdir /var/log/mongodb
| sudo vi /usr/local/mongodb/mongod.conf

3. Add the following text in mongod.conf:

| # Store data alongside MongoDB instead of the default, /data/db/
| dbpath = /usr/local/mongodb_data
| # Only accept local connections
| bind_ip =

4. Save the file and exit

5. If you want mongodb to be started every time your mac is rebooted, complete the following steps:

| # Enter the following commmand:
| sudo vi /Library/LaunchDaemons/org.mongodb.mongod.plist

| # add the following text:

| <?xml version="1.0" encoding="UTF-8"?>
| <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" >
| "">
| <plist version="1.0">
| <dict>
| <key>Label</key>
| <string>org.mongodb.mongod</string>
| <key>ProgramArguments</key>
| <array>
| <string>/usr/local/mongodb/bin/mongod</string>
| <string>run</string>
| <string>--config</string>
| <string>/usr/local/mongodb/mongod.conf</string>
| </array>
| <key>RunAtLoad</key>
| <true/>
| <key>KeepAlive</key>
| <true/>
| <key>WorkingDirectory</key>
| <string>/usr/local/mongodb</string>
| <key>StandardErrorPath</key>
| <string>/var/log/mongodb/output.log</string>
| <key>StandardOutPath</key>
| <string>/var/log/mongodb/output.log</string>
| </dict>
| </plist>

6. save the file and exit

7. Enter the following command:

| sudo launchctl load /Library/LaunchDaemons/org.mongodb.mongod.plist

8. To verify mongo is installed and running, open a browser window, and load this page: http://localhost:28017 You should see the mongodb status page. If you get an unable to connect, it may take several minutes for launchpad to initiate the new command.
mconnor (9) [Avatar] Offline
Re: mongoDB

found the answer here:

i had already done my install with Homebrew (which i love).

All i needed to do was open a terminal window and run mongod]

And then in a new terminal window, type mongo... and that results in:

Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
Questions? Try the support group
Server has startup warnings:
Thu Jan 9 15:39:28.494 [initandlisten]
Thu Jan 9 15:39:28.494 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
seasoup (37) [Avatar] Offline
Re: mongoDB
Yeah, I didn't have to do any of that you listed Mike, except for the autostart commands. mconnor, I also use brew and it works great as long as that is the only way you ever install things.

The command mongod starts the server, if you ctrl-c to get back to the prompt then you shut down the server. You have to open a different tab in the terminal and type mongo to connect to the server while it is running. Alternatively, you can start mongo up in the background, google around for it as there are a few ways to do that.