nodejs application - mongodb connection fails with error "ECONNREFUSED" - node.js

Background Information
I'm playing around with my first nodejs test app that is attempting to connect to a remote mongodb.
Problem:
The connection is failing with the following message:
admin#testdev:~/Documents/nodejs_tests$ sudo nodejs index.js
Server has started.
Request for / received
About to route a request for: /
inside db connect method
Request for /favicon.ico received
About to route a request for: /favicon.ico
inside db connect method
MongoError: connect ECONNREFUSED
null
MongoError: connect ECONNREFUSED
null
Here's the logic to connect:
function connect_nimble() {
console.log("inside db connect method");
MongoClient.connect("mongodb://10.1.1.1:27017/test", function(err,db) {
console.log(err);
console.log(db);
if(!err) {
console.log("booya! Connected to mongo");
return true;
}
});
}
What I've checked so far:
I've made sure that the database server is using port 27017. Here's what I see in the mongodb logs when i restart the database:
admin#mongotest:~$ tail -f /var/log/mongodb/mongod.log
2015-07-21T09:52:41.452-0500 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2015-07-21T09:52:41.452-0500 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2015-07-21T09:52:41.452-0500 I CONTROL [initandlisten]
2015-07-21T09:52:41.452-0500 I CONTROL [initandlisten] db version v3.0.4
2015-07-21T09:52:41.452-0500 I CONTROL [initandlisten] git version: 0481c958daeb2969800511e7475dc66986fa9ed5
2015-07-21T09:52:41.452-0500 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1f 6 Jan 2014
2015-07-21T09:52:41.452-0500 I CONTROL [initandlisten] build info: Linux ip-10-45-73-23 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49
2015-07-21T09:52:41.452-0500 I CONTROL [initandlisten] allocator: tcmalloc
2015-07-21T09:52:41.452-0500 I CONTROL [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1" }, storage: { dbPath: "/var/lib/mongodb" }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } }
**2015-07-21T09:52:41.470-0500 I NETWORK [initandlisten] waiting for connections on port 27017**
I've made sure I have a database called "test" by starting "mongo"... and then switching in and out of the test database using the "use test" / "use admin" commands.
I don't believe I have authorization turned on. This is what I have in the mongo.conf file:
# Turn on/off security. Off is currently the default
#noauth = true
#auth = true
And to prove it, in order to get into the test database on the server via command line, I just have to type "mongo" and then by default, I'm in the test database. So I think I can safely assume I don't have any authentication going on.
Just in case, I also checked netstat for the port number:
admin#mongotest:~$ sudo netstat -taupen | grep mongo
tcp 0 0 127.0.0.1:27017 0.0.0.0:* LISTEN 117 6465150 18792mongod
admin#mongotest:~$
I'm currently reading the manual to see if there's anything else I should be checking. I'm also reading through the various stackoverflow posts that are similar, but I haven't found me an answer yet.
Any suggestions?

I can see in your logs that Mongo is listening on 127.0.0.1. This is likely your problem. You will have to change the bind-ip address configuration setting to allow Mongo to listen to specific or all IP addresses. You can find how to do this here: Cannot connect to mongodb using machine ip

Open a terminal.
Type mongod & and check the stacktrace.
This is an example of a failing start
I STORAGE [initandlisten] exception in initAndListen: 29 Data directory /data/db not found., terminating
I NETWORK [initandlisten] shutdown: going to close listening sockets...
I NETWORK [initandlisten] shutdown: going to flush diaglog...
I CONTROL [initandlisten] now exiting
To fix this, Create the folder /data/db
In the terminal, type mkdir /data/db
Type againmongod
It works !!
[initandlisten] ** WARNING: Access control is not enabled for the database.
I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
I CONTROL [initandlisten]
I CONTROL [initandlisten]
I CONTROL [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000

Related

Impossible to connect to mongo after server shutdown

I am running a mongo cluster (v 3.4.1) on a remote Ubuntu server. This server had an unexpected shutdown yesterday. Since that, I cannot connect to mongo.
I connected by ssh to the server to check if mongo was running. It seems to be the case because if I use the mongo command, I get the following output:
MongoDB shell version v3.4.2
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.1
Server has startup warnings:
2017-09-28T08:01:43.906+0000 I STORAGE [initandlisten]
2017-09-28T08:01:43.906+0000 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2017-09-28T08:01:43.906+0000 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem
2017-09-28T08:01:44.204+0000 I CONTROL [initandlisten]
2017-09-28T08:01:44.204+0000 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-09-28T08:01:44.204+0000 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2017-09-28T08:01:44.204+0000 I CONTROL [initandlisten]
Now if I run "mongod" I get the exception:
...
2017-09-28T10:10:26.065+0200 I STORAGE [initandlisten] exception in initAndListen: 20 Attempted to create a lock file on a read-only directory: /data/db, terminating
2017-09-28T10:10:26.065+0200 I NETWORK [initandlisten] shutdown: going to close listening sockets...
...
I tried in sudo mode, I got:
...
2017-09-28T10:12:21.857+0200 E NETWORK [initandlisten] listen(): bind() failed Address already in use for socket: 0.0.0.0:27017
2017-09-28T10:12:21.857+0200 E NETWORK [initandlisten] addr already in use
2017-09-28T10:12:21.857+0200 E NETWORK [initandlisten] Failed to set up sockets during startup.
2017-09-28T10:12:21.857+0200 E STORAGE [initandlisten] Failed to set up listener: InternalError: Failed to set up sockets
2017-09-28T10:12:21.857+0200 I NETWORK [initandlisten] shutdown: going to close listening sockets...
...
Which would mean that an instance of mongo is already running...
Then I tried to kill mongo process, either with sudo service mongod stop or sudo pkill mongod or sudo kill <PID> after listing processes with ps -ef | grep mongo. But the process does not disappear from the list (seems that it restarts immediately).
So if I try to run sudo mongod --dbpath /data/db --repair (there is a mongod.lock file in the directory), I still get the error "Address already in use".
Any help would be really appreciated!

MongoDB - shutting down with code:100

I've been trying to set up MongoDB on my Ubuntu 16.04.2 LTS (GNU/Linux 4.4.0-22-generic x86_64) VPS and I've been running into a few problems. I am running as a user on my server that has root access but not using the root account itself.
I started to notice the problem when I was executing db.createUser() on the admin database so I could add other users and I was getting this error:
not authorized to execute command
So I then proceeded to uninstall and install again using the tutorial as provided on the website: https://docs.mongodb.com/v3.2/tutorial/install-mongodb-on-ubuntu/
Now when I'm on stage 2 Verify that MongoDB has started successfully on the Run MongoDB Community Edition section, that is I look at my output from the file /var/log/mongodb/mongod.log, I get the following:
2017-04-14T14:23:09.309+0200 I CONTROL [main] ***** SERVER RESTARTED *****
2017-04-14T14:23:09.316+0200 I CONTROL [initandlisten] MongoDB starting : pid=9691 port=27017 dbpath=/var/lib/mongodb 64-bit host=vps338741
2017-04-14T14:23:09.316+0200 I CONTROL [initandlisten] db version v3.4.3
2017-04-14T14:23:09.316+0200 I CONTROL [initandlisten] git version: f07437fb5a6cca07c10bafa78365456eb1d6d5e1
2017-04-14T14:23:09.316+0200 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2g 1 Mar 2016
2017-04-14T14:23:09.316+0200 I CONTROL [initandlisten] allocator: tcmalloc
2017-04-14T14:23:09.316+0200 I CONTROL [initandlisten] modules: none
2017-04-14T14:23:09.316+0200 I CONTROL [initandlisten] build environment:
2017-04-14T14:23:09.316+0200 I CONTROL [initandlisten] distmod: ubuntu1604
2017-04-14T14:23:09.316+0200 I CONTROL [initandlisten] distarch: x86_64
2017-04-14T14:23:09.316+0200 I CONTROL [initandlisten] target_arch: x86_64
2017-04-14T14:23:09.316+0200 I CONTROL [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1", port: 27017 }, storage: { dbPath: "/var/lib/mongodb", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log", quiet: true } }
2017-04-14T14:23:09.349+0200 I STORAGE [initandlisten]
2017-04-14T14:23:09.349+0200 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2017-04-14T14:23:09.349+0200 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem
2017-04-14T14:23:09.349+0200 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=464M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2017-04-14T14:23:09.366+0200 E STORAGE [initandlisten] WiredTiger error (2) [1492172589:366629][9691:0x7f1755946cc0], file:WiredTiger.wt, connection: /var/lib/mongodb/WiredTiger.wt: handle-open: open: No such file or directory
2017-04-14T14:23:09.367+0200 I - [initandlisten] Assertion: 28595:2: No such file or directory src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp 267
2017-04-14T14:23:09.367+0200 I STORAGE [initandlisten] exception in initAndListen: 28595 2: No such file or directory, terminating
2017-04-14T14:23:09.367+0200 I NETWORK [initandlisten] shutdown: going to close listening sockets...
2017-04-14T14:23:09.367+0200 I NETWORK [initandlisten] removing socket file: /tmp/mongodb-27017.sock
2017-04-14T14:23:09.367+0200 I NETWORK [initandlisten] shutdown: going to flush diaglog...
2017-04-14T14:23:09.367+0200 I CONTROL [initandlisten] now exiting
2017-04-14T14:23:09.367+0200 I CONTROL [initandlisten] shutting down with code:100
I've looked around and it is not the same error as found here, because that is to do with the fact there isn't an /data/db folder which I have. From that log I can see it is something to do with this line:
2017-04-14T14:23:09.366+0200 E STORAGE [initandlisten] WiredTiger error (2) [1492172589:366629][9691:0x7f1755946cc0], file:WiredTiger.wt, connection: /var/lib/mongodb/WiredTiger.wt: handle-open: open: No such file or directory
Which is true, when I go to /var/lib/mongodb and do ls -l it results with:
drwxr-xr-x 2 mongodb mongodb 4096 Apr 14 14:10 journal
-rw-r--r-- 1 mongodb mongodb 0 Apr 14 14:02 mongod.lock
-rw-r--r-- 1 mongodb mongodb 0 Apr 14 14:10 WiredTiger
-rw-r--r-- 1 mongodb mongodb 21 Apr 14 14:10 WiredTiger.lock
-rw-r--r-- 1 mongodb mongodb 1004 Apr 14 14:10 WiredTiger.turtle
But I don't know if I should manually create that file as not seen this problem elsewhere. I made sure that mongodb user has permissions on these files too as stated in the answer to this question, but still no luck.
I'm really at a loss as to what to do, any help would be very appreciated as this is my like fifth attempt at getting it working!
Thanks!
If you created the mkdir -p /data/db maybe there is a chance that you must start your server with the following command : sudo mongod
macOS/OSX : https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/
try :
sudo service mongod start ;
then run the mongodb with:
mongo
This is a known bug in MongoDB, check the report
Your problem is not that files are missing in general, it's that they go missing when you restart after a clean shutdown. Your problem is not related to the /data/db directory but more to WiredTiger.wt file that is missing after a restart.
Oct 1 20:00:44 alpha mongod.27017[1074]: [initandlisten] WiredTiger
(2) [1443729644:306783][1074:0x7fdba8fd4bc0], file:WiredTiger.wt,
connection: /data/db/WiredTiger.wt: No such file or directory
The bug report talks about the same thing.
Try:
I would suggest try and disable WiredTiger in the config file.
MongoDB Config Options
WiredTiger
UPDATE: To disable WiredTiger you have to change the storage.engine option in your mongo config file, by default mongod uses WiredTiger but you can also use InMemory LINK
Make a directory
sudo mkdir /data/db
Provide access to the directory
sudo chown -R $USER /data/db
Then run
mongod
If you get port already in use the stop mongod, it might be running in the background
sudo service mongod stop
If the last line is
waiting for connections on port 27017
then the mongod is working
This command helped me:
mongod --dbpath /data/db --repair
for me the 'answer' was to execute the following command (since service mongod start and just mongod failed)
sudo mongod --fork --port 27017 --replSet admin --logpath /data/log/mongo.log
I did not need to turn off wired tiger
Docker container:
In my case, I was using a docker container running
mongodb:
image: 'bitnami/mongodb:latest'
user: root
command: "chown -R $USER /bitnami/mongodb"
volumes:
- '/var/www/mongodb_data:/bitnami'
environment:
- MONGODB_USERNAME=bn_parse
- MONGODB_PASSWORD=3yfQexfqcc
- MONGODB_DATABASE=bitnami_parse
I migrated the docker host to other VPS/VM (aws is too expensive).
I added temporarily the command "chown -R $USER /bitnami/mongodb" to change the owner of that folder /bitnami/mongodb. It worked.
sudo mdkir data/db
sudo service mongod stop
sudo mongod
mongosh
this fixed it for me on ubuntu 22.04 after hours and hours of hunting down solutions

Mongodb won't start - reason: errno:111 Connection refused

All of a sudden I can't get mongodb to work.
Usually I will start with
mongo
however I get this when trying to start.
MongoDB shell version: 3.0.6
connecting to: test
2016-10-11T15:36:56.462+0100 W NETWORK Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2016-10-11T15:36:56.464+0100 E QUERY Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed
at connect (src/mongo/shell/mongo.js:179:14)
at (connect):1:6 at src/mongo/shell/mongo.js:179
exception: connect failed
I haven't updated anything on the server or even logged into it until the website broke. Any ideas why this is happening? I have tried to comment out the bind_ip but I don't get why it would just stop working and failing to start.
I have also tried
sudo service mongo start
mongod start/running, process 1529
Then when I tried -
sudo service mongod status
mongod stop/waiting.
I can't start my nodejs app because it returns
/node_modules/mongoose/node_modules/mongodb/lib/server.js:22‌​8 process.nextTick(function() { throw err; }) ^ Error: connect ECONNREFUSED at exports._errnoException (util.js:746:11) at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1010:19)
I think that is because mongodb isn't starting correctly but not sure.
The error produces this
2016-10-11T15:40:30.400+0100 E JOURNAL [initandlisten] Insufficient free space for journal files
2016-10-11T15:40:30.400+0100 I JOURNAL [initandlisten] Please make at least 3379MB available in /var/lib/mongodb/journal or use --smallfiles
2016-10-11T15:40:30.400+0100 I JOURNAL [initandlisten]
2016-10-11T15:40:30.402+0100 I STORAGE [initandlisten] exception in initAndListen: 15926 Insufficient free space for journals, terminating
2016-10-11T15:40:30.402+0100 I CONTROL [initandlisten] now exiting
2016-10-11T15:40:30.402+0100 I NETWORK [initandlisten] shutdown: going to close listening sockets...
2016-10-11T15:40:30.402+0100 I NETWORK [initandlisten] removing socket file: /tmp/mongodb-27017.sock
2016-10-11T15:40:30.402+0100 I NETWORK [initandlisten] shutdown: going to flush diaglog...
2016-10-11T15:40:30.402+0100 I NETWORK [initandlisten] shutdown: going to close sockets...
2016-10-11T15:40:30.402+0100 I STORAGE [initandlisten] shutdown: waiting for fs preallocator...
2016-10-11T15:40:30.402+0100 I STORAGE [initandlisten] shutdown: final commit...
2016-10-11T15:40:30.402+0100 I STORAGE [initandlisten] shutdown: closing all files...
2016-10-11T15:40:30.402+0100 I STORAGE [initandlisten] closeAllFiles() finished
2016-10-11T15:40:30.402+0100 I CONTROL [initandlisten] dbexit: rc: 100
2016-10-11T15:45:36.614+0100 I CONTROL ***** SERVER RESTARTED *****
2016-10-11T15:45:36.642+0100 E NETWORK [initandlisten] Failed to unlink socket file /tmp/mongodb-27017.sock errno:1 Operation not permitted
2016-10-11T15:45:36.642+0100 I - [initandlisten] Fatal Assertion 28578
2016-10-11T15:45:36.642+0100 I - [initandlisten]
***aborting after fassert() failure
2016-10-11T15:46:21.636+0100 I CONTROL ***** SERVER RESTARTED *****
2016-10-11T15:46:21.663+0100 E NETWORK [initandlisten] Failed to unlink socket file /tmp/mongodb-27017.sock errno:1 Operation not permitted
2016-10-11T15:46:21.663+0100 I - [initandlisten] Fatal Assertion 28578
2016-10-11T15:46:21.663+0100 I - [initandlisten]
I broswed to that dir and saw this!!! Why are those files so huge?
It seems that your error is similar to this
Removing the /tmp/mongodb-27017.sock file should do the trick.
Also check your disk space, as it seems the process is not starting because you are missing space for the journal files (check #dave-v comment below)
i open file /etc/mongodb.conf and put a # in begin of line bind_ip = 127.0.0.1 (#bind_ip = 127.0.0.1) .Then restart mongodb, it's work fine again !
Warning: If you use mongodb in online server, please don't do that. Hacker can attack for this port !
I faced same issue , solution is here
1) Once the mongo installation done by downloading or yum install
2) Create folder db under /home/scc-dev/data/db/
3)Goto mongo folder under bin , open terminal run the below command
sudo ./mongod dbpath /home/scc-dev/data/db
4)Check few lines command running in the console
5)open new terminal under bin run the below command
sudo ./mongo
6) type command -> show dbs (it should show default dbs like local..) then it is working fine
7) if you get error like Failed to connect to 127.0.0.1:27017, reason: errno: 61 Connection refused then
8) restart the linux m/c command - > /sbin/reboot (do the steps from 3 - issue will be resolved )
To open the any ports in linux m/c
sudo iptables -I INPUT -p tcp -m tcp --dport 27017 -j ACCEPT
sudo iptables-save

Cannot use mongoimport on vagrant

Following is my mongo.conf:
# mongod.conf
# Where and how to store data.
storage:
dbPath: /var/lib/mongodb
journal:
enabled: true
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
net:
port: 27017
# bindIp: 127.0.0.1
replication:
replSetName: rs0
oplogSizeMB: 250
I tried to import the data given here on the guest linux using
wget https://raw.githubusercontent.com/mongodb/docs-assets/primer-dataset/dataset.json
mongoimport --host=127.0.0.1 --port=27017 --db test --collection dataset --file dataset.json
and also tried on the host machine (mac):
mongoimport --host=127.0.0.1 --port=27071 --db test --collection dataset --file dataset.json
In both the cases I get the following output:
2016-02-25T11:01:56.280-0500 connected to: 127.0.0.1:27071
2016-02-25T11:01:59.278-0500 [........................] test.dataset 0.0 B/11.3 MB (0.0%)
2016-02-25T11:01:59.309-0500 [........................] test.dataset 0.0 B/11.3 MB (0.0%)
2016-02-25T11:01:59.309-0500 Failed: error checking connected node type: no reachable servers
2016-02-25T11:01:59.309-0500 imported 0 documents
All the requests that I make to port 27071 on the host system are forwarded to post 27017 on the linux guest. There are no connections issues as curl localhost:27071 gives It looks like you are trying to access MongoDB over HTTP on the native driver port.
UPDATE:
Following is the log of mongo:
2016-02-25T18:33:23.938+0000 I CONTROL ***** SERVER RESTARTED *****
2016-02-25T18:33:23.941+0000 I CONTROL [initandlisten] MongoDB starting : pid=4810 port=27017 dbpath=/var/lib/mongodb 64-bit host=vagrant-ubuntu-trusty-64
2016-02-25T18:33:23.941+0000 I CONTROL [initandlisten] db version v3.0.9
2016-02-25T18:33:23.941+0000 I CONTROL [initandlisten] git version: 20d60d3491908f1ae252fe452300de3978a040c7
2016-02-25T18:33:23.941+0000 I CONTROL [initandlisten] build info: Linux ip-10-732-9-221 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49
2016-02-25T18:33:23.941+0000 I CONTROL [initandlisten] allocator: tcmalloc
2016-02-25T18:33:23.941+0000 I CONTROL [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "0.0.0.0", port: 27017 }, replication: { oplogSizeMB: 250, replSetName: "rs0" }, storage: { dbPath: "/var/lib/mongodb", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } }
2016-02-25T18:33:23.969+0000 I JOURNAL [initandlisten] journal dir=/var/lib/mongodb/journal
2016-02-25T18:33:23.969+0000 I JOURNAL [initandlisten] recover : no journal files present, no recovery needed
2016-02-25T18:33:24.006+0000 I JOURNAL [durability] Durability thread started
2016-02-25T18:33:24.006+0000 I JOURNAL [journal writer] Journal writer thread started
2016-02-25T18:33:24.007+0000 I CONTROL [initandlisten]
2016-02-25T18:33:24.007+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2016-02-25T18:33:24.007+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2016-02-25T18:33:24.007+0000 I CONTROL [initandlisten]
2016-02-25T18:33:24.007+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2016-02-25T18:33:24.007+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2016-02-25T18:33:24.007+0000 I CONTROL [initandlisten]
2016-02-25T18:33:24.010+0000 I REPL [initandlisten] Did not find local replica set configuration document at startup; NoMatchingDocument Did not find replica set configuration document in local.system.replset
2016-02-25T18:33:24.011+0000 I NETWORK [initandlisten] waiting for connections on port 27017
If I try to do mongoimport --host=0.0.0.0 --port=27071 --db test --collection dataset --file dataset.json from the host system, following is added to the log:
2016-02-25T18:36:03.443+0000 I NETWORK [initandlisten] connection accepted from 10.0.2.2:51277 #1 (1 connection now open)
2016-02-25T18:36:06.479+0000 I NETWORK [conn1] end connection 10.0.2.2:51277 (0 connections now open)
and when I try this same command from the guest linux, I get:
2016-02-25T18:38:29.982+0000 I NETWORK [initandlisten] connection accepted from 127.0.0.1:59910 #2 (1 connection now open)
2016-02-25T18:38:32.994+0000 I NETWORK [conn2] end connection 127.0.0.1:59910 (0 connections now open)
Try to chance your bindIp param to 0.0.0.0, and restart the service.

MEAN.js Could not connect to MongoDB

in creating my app with MEAN.js can not do mongodb connect on port 27017 in any way.
I installed mongodb manually in directory
~$ ls -la /etc/init.d/mongod
output
lrwxrwxrwx 1 root root 56 Nov 4 20:45 /etc/init.d/mongod -> /home/myuser/projects/packages/linux-mongodb/bin/mongod
I try to run the file or `` server.js` grunt` the NASC repository command and got the following error:
Running node server.js i receive this output:
Application loaded using the "development" environment configuration
Failed to load c ++ bson extension, using pure JS version
Insecurely using http protocol
MEAN.JS application started on port 27017
Could not connect to MongoDB!
Error: connection closed
Repository URL:
https://github.com/meanjs/mean
Some hint of what might be?
I look forward personal contact.
Thanks in advance!
Link for reference:
https://stackoverflow.com/a/22557417/3332734
running cat /etc/mongod.conf
# mongod.conf
# Where to store the data.
# Note: if you run mongodb as a non-root user (recommended) you may
# need to create and set permissions for this directory manually,
# e.g., if the parent directory isn't mutable by the mongodb user.
dbpath=/var/lib/mongodb
###dbpath=/home/myuser/projects/packages/mongodb-linux/databases
#where to log
logpath=/var/log/mongodb/mongod.log
###logpath=/home/myuser/projects/packages/mongodb-linux/mongod.log
logappend=true
port = 27017
# Listen to local interface only. Comment out to listen on all interfaces.
bind_ip = 127.0.0.1
# Disables write-ahead journaling
# nojournal = true
# Enables periodic logging of CPU utilization and I/O wait
#cpu = true
# Turn on/off security. Off is currently the default
#noauth = true
#auth = true
# Verbose logging output.
#verbose = true
# Inspect all client data for validity on receipt (useful for
# developing drivers)
#objcheck = true
# Enable db quota management
#quota = true
# Set oplogging level where n is
# 0=off (default)
# 1=W
# 2=R
# 3=both
# 7=W+some reads
#diaglog = 0
# Ignore query hints
#nohints = true
# Enable the HTTP interface (Defaults to port 28017).
#httpinterface = true
httpinterface = true
# Turns off server-side scripting. This will result in greatly limited
# functionality
#noscripting = true
# Turns off table scans. Any query that would do a table scan fails.
#notablescan = true
# Disable data file preallocation.
#noprealloc = true
# Specify .ns file size for new databases.
# nssize = <size>
# Replication Options
# in replicated mongo databases, specify the replica set name here
#replSet=setname
# maximum size in megabytes for replication operation log
#oplogSize=1024
# path to a key file storing authentication info for connections
# between replica set members
#keyFile=/path/to/keyfile
Run mongo in console and retrieve output:
$ mongo
MongoDB shell version: 2.6.5
connecting to: test
2014-11-05T19:23:18.957-0200 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2014-11-05T19:23:18.958-0200 Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146
exception: connect failed
Run mongod in console and retrieve output:
$ mongod
mongod --help for help and startup options
2014-11-05T19:26:53.215-0200 [initandlisten] MongoDB starting : pid=3487 port=27017 dbpath=/data/db 64-bit host=francis-tosystems
2014-11-05T19:26:53.215-0200 [initandlisten] db version v2.6.5
2014-11-05T19:26:53.215-0200 [initandlisten] git version: e99d4fcb4279c0279796f237aa92fe3b64560bf6
2014-11-05T19:26:53.215-0200 [initandlisten] build info: Linux build8.nj1.10gen.cc 2.6.32-431.3.1.el6.x86_64 #1 SMP Fri Jan 3 21:39:27 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49
2014-11-05T19:26:53.215-0200 [initandlisten] allocator: tcmalloc
2014-11-05T19:26:53.215-0200 [initandlisten] options: {}
2014-11-05T19:26:53.215-0200 [initandlisten] exception in initAndListen: 10296
*********************************************************************
ERROR: dbpath (/data/db) does not exist.
Create this directory or give existing directory in --dbpath.
See http://dochub.mongodb.org/core/startingandstoppingmongo
*********************************************************************
, terminating
2014-11-05T19:26:53.215-0200 [initandlisten] dbexit:
2014-11-05T19:26:53.215-0200 [initandlisten] shutdown: going to close listening sockets...
2014-11-05T19:26:53.215-0200 [initandlisten] shutdown: going to flush diaglog...
2014-11-05T19:26:53.215-0200 [initandlisten] shutdown: going to close sockets...
2014-11-05T19:26:53.215-0200 [initandlisten] shutdown: waiting for fs preallocator...
2014-11-05T19:26:53.215-0200 [initandlisten] shutdown: lock for final commit...
2014-11-05T19:26:53.215-0200 [initandlisten] shutdown: final commit...
2014-11-05T19:26:53.215-0200 [initandlisten] shutdown: closing all files...
2014-11-05T19:26:53.216-0200 [initandlisten] closeAllFiles() finished
2014-11-05T19:26:53.216-0200 [initandlisten] dbexit: really exiting now
Or run mongod
$ mongod --config /etc/mongod.conf &
[1] 3568 2014-11-05T19:28:16.867-0200 SEVERE: Failed global initialization: FileNotOpen Failed to open "/var/log/mongodb/mongod.log"
EDIT
I am no longer using MEAN.js, but I continue my studies with MongoDB and node.js
The problem was that I did not know how to start mongodb to connect to the database
This year I learned a lot about mongodb and node.js and I understood what I needed to do.
With your help I have three steps:
Open a console with mongod --dbpath /project/path-do-database/
I connected my API to mongodb, passing the right port
Open a second console by starting the node.js API with node ornodemon and passing the project's main javascript file.
Basically, you need to have 2 terminals running at the same folder.
One for mongoDB, one for your application.
On the first terminal,
1>> npm install -g meanjs
1>> yo meanjs
then fill up your application name, author name, etc.
1>> npm install
Open up a 2nd terminal to start the mongodb server
2>> mongod
Go back to the first terminal and run it
1>> npm start
You are starting your meanjs app on the same port as your mongodb server (27017). If you do not specify a port for meanjs, it will start on 3000 in a development environment.
I know it is probably late, but error logs says it all:
ERROR: dbpath (/data/db) does not exist.
I belive you need to create /data/db folders or it was created somewhere else.
It is already answered here:
mongodb Mongod complains that there is no /data/db folder

Resources