What's the safest way to shut down MongoDB when running as a Windows Service? - windows

I have a single instance of MongoDB 2.4.8 running on Windows Server 2012 R2. MongoDB is installed as a Windows Service. I have journalling enabled.
The MongoDB documentation suggests that the MongoDB service should just be shut down via the Windows Service Control Manager:
net stop MongoDB
When I did this recently, the following was logged and I ended up with a non-zero byte mongod.lock file on disk. (I used the --repair option to fix this but it turns out this probably wasn't necessary as I had journalling enabled.)
Thu Nov 21 11:08:12.011 [serviceShutdown] got SERVICE_CONTROL_STOP request from Windows Service Control Manager, will terminate after current cmd ends
Thu Nov 21 11:08:12.043 [serviceShutdown] now exiting
Thu Nov 21 11:08:12.043 dbexit:
Thu Nov 21 11:08:12.043 [serviceShutdown] shutdown: going to close listening sockets...
Thu Nov 21 11:08:12.043 [serviceShutdown] closing listening socket: 1492
Thu Nov 21 11:08:12.043 [serviceShutdown] closing listening socket: 1500
Thu Nov 21 11:08:12.043 [serviceShutdown] shutdown: going to flush diaglog...
Thu Nov 21 11:08:12.043 [serviceShutdown] shutdown: going to close sockets...
Thu Nov 21 11:08:12.043 [serviceShutdown] shutdown: waiting for fs preallocator...
Thu Nov 21 11:08:12.043 [serviceShutdown] shutdown: lock for final commit...
Thu Nov 21 11:08:12.043 [serviceShutdown] shutdown: final commit...
Thu Nov 21 11:08:12.043 [conn1333] end connection 127.0.0.1:51612 (18 connections now open)
Thu Nov 21 11:08:12.043 [conn1331] end connection 127.0.0.1:51610 (18 connections now open)
...snip...
Thu Nov 21 11:08:12.043 [conn1322] end connection 10.1.2.212:53303 (17 connections now open)
Thu Nov 21 11:08:12.043 [conn1337] end connection 127.0.0.1:51620 (18 connections now open)
Thu Nov 21 11:08:12.839 [serviceShutdown] shutdown: closing all files...
Thu Nov 21 11:08:14.683 [serviceShutdown] Progress: 5/163 3% (File Closing Progress)
Thu Nov 21 11:08:16.012 [serviceShutdown] Progress: 6/163 3% (File Closing Progress)
...snip...
Thu Nov 21 11:08:52.030 [serviceShutdown] Progress: 143/163 87% (File Closing Progress)
Thu Nov 21 11:08:54.092 [serviceShutdown] Progress: 153/163 93% (File Closing Progress)
Thu Nov 21 11:08:55.405 [serviceShutdown] closeAllFiles() finished
Thu Nov 21 11:08:55.405 [serviceShutdown] journalCleanup...
Thu Nov 21 11:08:55.405 [serviceShutdown] removeJournalFiles
Thu Nov 21 11:09:05.578 [DataFileSync] ERROR: Client::shutdown not called: DataFileSync
The last line is my main concern.
I'm also interested in how MongoDB is able to take longer to shut down than Windows normally allows for service shutdown? At what point is it safe to shut down the machine without checking the log file?

Related

Jmeter test, takes always the same time between start and finish

Jmeter is taking always the same time to finish remote test. The jmx script is simple and there is no time configured on it, and there are just one request (only 84ms in local test).
It happens only on remote test, in local test is ok.
Starting the test on host x.x.x.x # Thu Aug 14 09:31:43 BRT 2014 (1408019503091)
Finished the test on host x.x.x.x # Thu Aug 14 09:34:43 BRT 2014 (1408019683082)
Starting the test on host x.x.x.x # Thu Aug 14 09:35:53 BRT 2014 (1408019753107)
Finished the test on host x.x.x.x # Thu Aug 14 09:38:53 BRT 2014 (1408019933091)
Starting the test on host x.x.x.x # Thu Aug 14 09:40:33 BRT 2014 (1408020033110)
Finished the test on host x.x.x.x # Thu Aug 14 09:43:33 BRT 2014 (1408020213100)
Starting the test on host x.x.x.x # Thu Aug 14 10:03:23 BRT 2014 (1408021403158)
Finished the test on host x.x.x.x # Thu Aug 14 10:06:23 BRT 2014 (1408021583154)
Starting the test on host x.x.x.x # Thu Aug 14 10:07:53 BRT 2014 (1408021673181)
Finished the test on host x.x.x.x # Thu Aug 14 10:10:53 BRT 2014 (1408021853164)
Starting the test on host x.x.x.x # Thu Aug 14 10:25:23 BRT 2014 (1408022723204)
Finished the test on host x.x.x.x # Thu Aug 14 10:28:23 BRT 2014 (1408022903204)
Starting the test on host x.x.x.x # Thu Aug 14 10:33:13 BRT 2014 (1408023193224)
Finished the test on host x.x.x.x # Thu Aug 14 10:36:53 BRT 2014 (1408023413225)

Remove MongoDB from auto starting on login

I installed MongoDB through home brew on osx lion but for some reason, it keeps starting up automatically when I login.
>:mongod
Mon Aug 12 20:35:31.270 [initandlisten] MongoDB starting : pid=52473 port=27017 dbpath=/usr/local/var/mongodb 64-bit host=Mah-iMac.local
Mon Aug 12 20:35:31.270 [initandlisten] db version v2.4.5
Mon Aug 12 20:35:31.270 [initandlisten] git version: a2ddc68ba7c9cee17bfe69ed840383ec3506602b
Mon Aug 12 20:35:31.270 [initandlisten] build info: Darwin bs-osx-106-x86-64-2.10gen.cc 10.8.0 Darwin Kernel Version 10.8.0: Tue Jun 7 16:32:41 PDT 2011; root:xnu-1504.15.3~1/RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_49
Mon Aug 12 20:35:31.271 [initandlisten] allocator: system
Mon Aug 12 20:35:31.271 [initandlisten] options: { bind_ip: "127.0.0.1", config: "/usr/local/etc/mongod.conf", dbpath: "/usr/local/var/mongodb" }
Mon Aug 12 20:35:31.272 [initandlisten] journal dir=/usr/local/var/mongodb/journal
Mon Aug 12 20:35:31.272 [initandlisten] recover : no journal files present, no recovery needed
Mon Aug 12 20:35:31.328 [initandlisten] ERROR: listen(): bind() failed errno:48 Address already in use for socket: 127.0.0.1:27017
Mon Aug 12 20:35:31.328 [initandlisten] ERROR: addr already in use
Mon Aug 12 20:35:31.328 [websvr] ERROR: listen(): bind() failed errno:48 Address already in use for socket: 127.0.0.1:28017
Mon Aug 12 20:35:31.328 [initandlisten] now exiting
Mon Aug 12 20:35:31.328 dbexit: Mon Aug 12 20:35:31.328 [websvr] ERROR: addr already in use
Mon Aug 12 20:35:31.328 [initandlisten] shutdown: going to close listening sockets...
Mon Aug 12 20:35:31.328 [initandlisten] shutdown: going to flush diaglog...
Mon Aug 12 20:35:31.328 [initandlisten] shutdown: going to close sockets...
Mon Aug 12 20:35:31.328 [initandlisten] shutdown: waiting for fs preallocator...
Mon Aug 12 20:35:31.328 [initandlisten] shutdown: lock for final commit...
Mon Aug 12 20:35:31.328 [initandlisten] shutdown: final commit...
Mon Aug 12 20:35:31.335 [initandlisten] shutdown: closing all files...
Mon Aug 12 20:35:31.337 [initandlisten] closeAllFiles() finished
Mon Aug 12 20:35:31.338 [initandlisten] journalCleanup...
Mon Aug 12 20:35:31.338 [initandlisten] removeJournalFiles
Mon Aug 12 20:35:31.338 [initandlisten] shutdown: removing fs lock...
Mon Aug 12 20:35:31.338 dbexit: really exiting now
How can I remove this from starting up automatically? I don't really use mongo a lot so its kinda not needed and when I do need to use it, it's kinda annoying to get an error when I try to fire it up :/
It should be either:
launchctl unload -w ~/Library/LaunchAgents/org.mongodb.mongod.plist
or
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist

Regarding changing bash file and making new directory for mongodb

I am trying to play around with mongodb using osx, and for doing so I am required to create a directory using the following inside the directory of my mongodb exe
mkdir /data/db
however when I attempt to do so, my command prompt return the following
$ mkdir /data/db
mkdir: /data: No such file or directory
currently my mongodb exe are not command line enabled, that is it is not in the path of the bash, does anyone know how to make the mongodb program global?
thanks in advance
added
so I tried both adding the bash file, and
$ sudo mkdir -p /data/db/
$ mkdir -p /data/db
simply typing
$ mongod
still doesn't work, I have to type the following
$ ./mongod
but it gives the following
$ ./mongod
./mongod --help for help and startup options
Thu Jul 18 13:27:37.558 [initandlisten] MongoDB starting : pid=1042 port=27017 dbpath=/data/db/ 64-bit host=unknown20c9d0b97f55.att.net
Thu Jul 18 13:27:37.559 [initandlisten]
Thu Jul 18 13:27:37.559 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
Thu Jul 18 13:27:37.559 [initandlisten] db version v2.4.5
Thu Jul 18 13:27:37.559 [initandlisten] git version: a2ddc68ba7c9cee17bfe69ed840383ec3506602b
Thu Jul 18 13:27:37.559 [initandlisten] build info: Darwin bs-osx-106-x86-64-2.10gen.cc 10.8.0 Darwin Kernel Version 10.8.0: Tue Jun 7 16:32:41 PDT 2011; root:xnu- 1504.15.3~1/RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_49
Thu Jul 18 13:27:37.559 [initandlisten] allocator: system
Thu Jul 18 13:27:37.559 [initandlisten] options: {}
Thu Jul 18 13:27:37.559 [initandlisten] exception in initAndListen: 10309 Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
Thu Jul 18 13:27:37.559 dbexit:
Thu Jul 18 13:27:37.559 [initandlisten] shutdown: going to close listening sockets...
Thu Jul 18 13:27:37.559 [initandlisten] shutdown: going to flush diaglog...
Thu Jul 18 13:27:37.559 [initandlisten] shutdown: going to close sockets...
Thu Jul 18 13:27:37.559 [initandlisten] shutdown: waiting for fs preallocator...
Thu Jul 18 13:27:37.559 [initandlisten] shutdown: lock for final commit...
Thu Jul 18 13:27:37.559 [initandlisten] shutdown: final commit...
Thu Jul 18 13:27:37.559 [initandlisten] shutdown: closing all files...
Thu Jul 18 13:27:37.559 [initandlisten] closeAllFiles() finished
Thu Jul 18 13:27:37.559 [initandlisten] shutdown: removing fs lock...
Thu Jul 18 13:27:37.559 [initandlisten] couldn't remove fs lock errno:9 Bad file descriptor
Thu Jul 18 13:27:37.559 dbexit: really exiting now
edit 2:
tried
sudo chown 'myusername' /data/db
neither
sudo ./mongod
or
./mongod
worked
edit 3:
$ ./mongod
./mongod --help for help and startup options
Thu Jul 18 14:11:35.144 [initandlisten] MongoDB starting : pid=1550 port=27017 dbpath=/data/db/ 64-bit host=unknown20c9d0b97f55.att.net
Thu Jul 18 14:11:35.145 [initandlisten]
Thu Jul 18 14:11:35.145 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
Thu Jul 18 14:11:35.145 [initandlisten] db version v2.4.5
Thu Jul 18 14:11:35.145 [initandlisten] git version: a2ddc68ba7c9cee17bfe69ed840383ec3506602b
Thu Jul 18 14:11:35.145 [initandlisten] build info: Darwin bs-osx-106-x86-64-2.10gen.cc 10.8.0 Darwin Kernel Version 10.8.0: Tue Jun 7 16:32:41 PDT 2011; root:xnu-1504.15.3~1/RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_49
Thu Jul 18 14:11:35.145 [initandlisten] allocator: system
Thu Jul 18 14:11:35.145 [initandlisten] options: {}
Thu Jul 18 14:11:35.145 [initandlisten] exception in initAndListen: 10309 Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
Thu Jul 18 14:11:35.145 dbexit:
Thu Jul 18 14:11:35.145 [initandlisten] shutdown: going to close listening sockets...
Thu Jul 18 14:11:35.145 [initandlisten] shutdown: going to flush diaglog...
Thu Jul 18 14:11:35.145 [initandlisten] shutdown: going to close sockets...
Thu Jul 18 14:11:35.145 [initandlisten] shutdown: waiting for fs preallocator...
Thu Jul 18 14:11:35.145 [initandlisten] shutdown: lock for final commit...
Thu Jul 18 14:11:35.145 [initandlisten] shutdown: final commit...
Thu Jul 18 14:11:35.145 [initandlisten] shutdown: closing all files...
Thu Jul 18 14:11:35.145 [initandlisten] closeAllFiles() finished
Thu Jul 18 14:11:35.145 [initandlisten] shutdown: removing fs lock...
Thu Jul 18 14:11:35.145 [initandlisten] couldn't remove fs lock errno:9 Bad file descriptor
Thu Jul 18 14:11:35.145 dbexit: really exiting now
$ sudo ./mongod
./mongod --help for help and startup options
Thu Jul 18 14:11:43.450 [initandlisten] MongoDB starting : pid=1552 port=27017 dbpath=/data/db/ 64-bit host=unknown20c9d0b97f55.att.net
Thu Jul 18 14:11:43.451 [initandlisten]
Thu Jul 18 14:11:43.451 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
Thu Jul 18 14:11:43.451 [initandlisten] db version v2.4.5
Thu Jul 18 14:11:43.451 [initandlisten] git version: a2ddc68ba7c9cee17bfe69ed840383ec3506602b
Thu Jul 18 14:11:43.451 [initandlisten] build info: Darwin bs-osx-106-x86-64-2.10gen.cc 10.8.0 Darwin Kernel Version 10.8.0: Tue Jun 7 16:32:41 PDT 2011; root:xnu-1504.15.3~1/RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_49
Thu Jul 18 14:11:43.451 [initandlisten] allocator: system
Thu Jul 18 14:11:43.451 [initandlisten] options: {}
Thu Jul 18 14:11:43.451 [initandlisten] journal dir=/data/db/journal
Thu Jul 18 14:11:43.451 [initandlisten] recover : no journal files present, no recovery needed
Thu Jul 18 14:11:43.489 [initandlisten] ERROR: listen(): bind() failed errno:48 Address already in use for socket: 0.0.0.0:27017
Thu Jul 18 14:11:43.489 [websvr] ERROR: listen(): bind() failed errno:48 Address already in use for socket: 0.0.0.0:28017
Thu Jul 18 14:11:43.489 [initandlisten] ERROR: addr already in use
Thu Jul 18 14:11:43.489 [websvr] ERROR: addr already in use
Thu Jul 18 14:11:43.489 [initandlisten] now exiting
Thu Jul 18 14:11:43.489 dbexit:
Thu Jul 18 14:11:43.489 [initandlisten] shutdown: going to close listening sockets...
Thu Jul 18 14:11:43.489 [initandlisten] shutdown: going to flush diaglog...
Thu Jul 18 14:11:43.489 [initandlisten] shutdown: going to close sockets...
Thu Jul 18 14:11:43.489 [initandlisten] shutdown: waiting for fs preallocator...
Thu Jul 18 14:11:43.489 [initandlisten] shutdown: lock for final commit...
Thu Jul 18 14:11:43.489 [initandlisten] shutdown: final commit...
Thu Jul 18 14:11:43.500 [initandlisten] shutdown: closing all files...
Thu Jul 18 14:11:43.505 [initandlisten] closeAllFiles() finished
Thu Jul 18 14:11:43.505 [initandlisten] journalCleanup...
Thu Jul 18 14:11:43.505 [initandlisten] removeJournalFiles
Thu Jul 18 14:11:43.506 [initandlisten] shutdown: removing fs lock...
Thu Jul 18 14:11:43.506 dbexit: really exiting now
edit 4:
$ sudo killall mongod
Password:
$ sudo rm -rf /data/db
$ sudo mkdir -p /data/db
$ sudo chown xxxxx/data/db
usage: chown [-fhv] [-R [-H | -L | -P]] owner[:group] file ...
chown [-fhv] [-R [-H | -L | -P]] :group file ...
$ ./mongod
./mongod --help for help and startup options
Thu Jul 18 14:27:04.047 [initandlisten] MongoDB starting : pid=417 port=27017 dbpath=/data/db/ 64-bit host=unknown20c9d0b97f55.att.net
Thu Jul 18 14:27:04.047 [initandlisten]
Thu Jul 18 14:27:04.047 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
Thu Jul 18 14:27:04.047 [initandlisten] db version v2.4.5
Thu Jul 18 14:27:04.047 [initandlisten] git version: a2ddc68ba7c9cee17bfe69ed840383ec3506602b
Thu Jul 18 14:27:04.047 [initandlisten] build info: Darwin bs-osx-106-x86-64-2.10gen.cc 10.8.0 Darwin Kernel Version 10.8.0: Tue Jun 7 16:32:41 PDT 2011; root:xnu-1504.15.3~1/RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_49
Thu Jul 18 14:27:04.047 [initandlisten] allocator: system
Thu Jul 18 14:27:04.047 [initandlisten] options: {}
Thu Jul 18 14:27:04.110 [initandlisten] exception in initAndListen: 10309 Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
Thu Jul 18 14:27:04.110 dbexit:
Thu Jul 18 14:27:04.110 [initandlisten] shutdown: going to close listening sockets...
Thu Jul 18 14:27:04.110 [initandlisten] shutdown: going to flush diaglog...
Thu Jul 18 14:27:04.110 [initandlisten] shutdown: going to close sockets...
Thu Jul 18 14:27:04.110 [initandlisten] shutdown: waiting for fs preallocator...
Thu Jul 18 14:27:04.110 [initandlisten] shutdown: lock for final commit...
Thu Jul 18 14:27:04.110 [initandlisten] shutdown: final commit...
Thu Jul 18 14:27:04.110 [initandlisten] shutdown: closing all files...
Thu Jul 18 14:27:04.119 [initandlisten] closeAllFiles() finished
Thu Jul 18 14:27:04.119 [initandlisten] shutdown: removing fs lock...
Thu Jul 18 14:27:04.119 [initandlisten] couldn't remove fs lock errno:9 Bad file descriptor
Thu Jul 18 14:27:04.119 dbexit: really exiting now
Can you add it to your bashrc?
cd
nano .bashrc
mongodb="path_To_mongodb.exe" ## add this to bashrc, save and quit. Then restart terminal.
Make sure there no spaces. Replace "path_To_mongodb.exe" with the actual path to your exe. Make sure it's in the right file, and saved, and terminal restarted, and if you're trying it in a script, expand the variables by adding
shopt -s expand_aliases
source ~/.bashrc
to the start of the script.

Mongodb shell mongo: Only one usage of each socket address (protocol/network address/port) is normally permitted. for socket: 0.0.0.0:27017

It was fine 2 days ago, Now mongod does not work. Even echo ps -A | grep mongo printed nothing, yet it warns about error: "Only one usage of each socket address". How to kill that? I have also tried with different random port. How can they fail as well?
D:\mongodb-win32-x86_64-2.2.3\bin>mongod
mongod --help for help and startup options
Sun Mar 03 18:10:03 [initandlisten] MongoDB starting : pid=6292 port=27017 dbpat
h=\data\db\ 64-bit host=Sadaf
Sun Mar 03 18:10:03 [initandlisten] db version v2.2.3, pdfile version 4.5
Sun Mar 03 18:10:03 [initandlisten] git version: f570771a5d8a3846eb7586eaffcf4c2
f4a96bf08
Sun Mar 03 18:10:03 [initandlisten] build info: windows sys.getwindowsversion(ma
jor=6, minor=1, build=7601, platform=2, service_pack='Service Pack 1') BOOST_LIB
_VERSION=1_49
Sun Mar 03 18:10:03 [initandlisten] options: {}
Sun Mar 03 18:10:03 [initandlisten] journal dir=/data/db/journal
Sun Mar 03 18:10:03 [initandlisten] recover : no journal files present, no recov
ery needed
Sun Mar 03 18:10:04 [initandlisten] ERROR: listen(): bind() failed errno:10048 O
nly one usage of each socket address (protocol/network address/port) is normally
permitted. for socket: 0.0.0.0:27017
Sun Mar 03 18:10:04 [websvr] ERROR: listen(): bind() failed errno:10048 Only one
usage of each socket address (protocol/network address/port) is normally permit
ted. for socket: 0.0.0.0:28017
Sun Mar 03 18:10:04 [initandlisten] now exiting
Sun Mar 03 18:10:04 dbexit:
Sun Mar 03 18:10:04 [initandlisten] shutdown: going to close listening sockets..
.
Sun Mar 03 18:10:04 [initandlisten] shutdown: going to flush diaglog...
Sun Mar 03 18:10:04 [initandlisten] shutdown: going to close sockets...
Sun Mar 03 18:10:04 [initandlisten] shutdown: waiting for fs preallocator...
Sun Mar 03 18:10:04 [initandlisten] shutdown: lock for final commit...
Sun Mar 03 18:10:04 [initandlisten] shutdown: final commit...
Sun Mar 03 18:10:04 [initandlisten] shutdown: closing all files...
Sun Mar 03 18:10:04 [initandlisten] closeAllFiles() finished
Sun Mar 03 18:10:04 [initandlisten] journalCleanup...
Sun Mar 03 18:10:04 [initandlisten] removeJournalFiles
Sun Mar 03 18:10:04 [initandlisten] shutdown: removing fs lock...
Sun Mar 03 18:10:04 dbexit: really exiting now
D:\mongodb-win32-x86_64-2.2.3\bin>echo ps -A | grep mongo
D:\mongodb-win32-x86_64-2.2.3\bin>
In the command prompt type the following command
netstat -a -n -o | find "27017"
This will list all processes which are using port "27017" along with the PID.
Locate the PID using "27017".
For example if the PID is 10580, to kill it
taskkill /f /pid 10580
Now start mongo.
Hope this helps.
try to start mongo on a different port: http://docs.mongodb.org/manual/reference/mongod/#cmdoption-mongod--port
to be sure what port you can use, execute the command Sriukanth Venugopalan mentioned, it will list the current ports being used.
Regards,
Moacy
Open command prompt in Administrator mode
run net stop MongoDB

Mongodb takes 3 minutes to connect

Just reinstalled Mongodb on my mac (fresh install of mountain lion 10.8) and now my apps are taking ~3 mins to connect.
I put together a simple node script to test this:
var start = (new Date()).getTime();
var mongoose = require('mongoose');
var db = mongoose.connect('mongodb://localhost/passport-mongox',function(err){
var stop = (new Date()).getTime();
console.log('Took this long: ',(stop-start) / 1000 );
});
Both times were 175.273 and 175.316 seconds.
When I connect to an external, hosted mongodb it connects in less than a second,
Any idea why this would happen? Here is my mongo.log:
Fri Feb 1 12:43:25 [initandlisten] MongoDB starting : pid=2262 port=27017 dbpath=/usr/local/var/mongodb 64-bit host=w
Fri Feb 1 12:43:25 [initandlisten] db version v2.2.2, pdfile version 4.5
Fri Feb 1 12:43:25 [initandlisten] git version: d1b43b61a5308c4ad0679d34b262c5af9d664267
Fri Feb 1 12:43:25 [initandlisten] build info: Darwin bs-osx-106-x86-64-1.local 10.8.0 Darwin Kernel Version 10.8.0: Tue Jun 7 16:33:36 PDT 2011; root:xnu-1504.15.3~1/RELEASE_I386 i386 BOOST_LIB_VERSION=1_49
Fri Feb 1 12:43:25 [initandlisten] options: { bind_ip: "127.0.0.1", config: "/usr/local/etc/mongod.conf", dbpath: "/usr/local/var/mongodb", logappend: "true", logpath: "/usr/local/var/log/mongodb/mongo.log" }
Fri Feb 1 12:43:25 [initandlisten] journal dir=/usr/local/var/mongodb/journal
Fri Feb 1 12:43:25 [initandlisten] recover : no journal files present, no recovery needed
Fri Feb 1 12:43:26 [websvr] admin web console waiting for connections on port 28017
Fri Feb 1 12:43:26 [initandlisten] waiting for connections on port 27017
Fri Feb 1 12:44:05 [initandlisten] connection accepted from 127.0.0.1:52137 #1 (1 connection now open)
Fri Feb 1 12:44:40 [initandlisten] connection accepted from 127.0.0.1:52152 #2 (2 connections now open)
Fri Feb 1 12:45:15 [initandlisten] connection accepted from 127.0.0.1:52201 #3 (3 connections now open)
Fri Feb 1 12:45:50 [initandlisten] connection accepted from 127.0.0.1:52298 #4 (4 connections now open)
Fri Feb 1 12:46:25 [initandlisten] connection accepted from 127.0.0.1:52325 #5 (5 connections now open)
Fri Feb 1 12:51:26 [conn5] end connection 127.0.0.1:52325 (4 connections now open)
Fri Feb 1 12:51:26 [conn3] end connection 127.0.0.1:52201 (4 connections now open)
Fri Feb 1 12:51:26 [conn4] end connection 127.0.0.1:52298 (4 connections now open)
Fri Feb 1 12:51:26 [conn1] end connection 127.0.0.1:52137 (4 connections now open)
Fri Feb 1 12:51:26 [conn2] end connection 127.0.0.1:52152 (4 connections now open)
Answer from mongoose.js
Cause:
The underlying MongoDB driver defaults to looking for IPv6 addresses,
so the most likely cause is that your localhost DNS mapping isn't configured to handle IPv6.
Solution :
Use 127.0.0.1 instead of localhost or use the family option as shown in the connection docs.
mongoose.connect(url, {family:4}, function(err, connection) {
connection.db(your_db_name);
});
So the answer came from #AdamMeghji on twitter.
My hosts file has always looked like this:
127.0.0.1 localhost
127.0.0.1 test.com
127.0.0.1 wes.dev
I switched that to:
127.0.0.1 localhost test.com wes.dev
and connections went back to 0.015 seconds.

Resources