4

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:

  1. Open a console with mongod --dbpath /project/path-do-database/
  2. I connected my API to mongodb, passing the right port
  3. Open a second console by starting the node.js API with node ornodemon and passing the project's main javascript file.
Cœur
  • 37,241
  • 25
  • 195
  • 267
Francis Rodrigues
  • 1,470
  • 4
  • 25
  • 61

3 Answers3

3

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
Chee Loong Soon
  • 3,601
  • 3
  • 17
  • 21
2

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.

uwolfer
  • 4,356
  • 1
  • 25
  • 40
  • Regardless. The only solution was to install mongodb via apt-get, the only way to start alone. But I wanted to install only in pure javascript, only this one did not start alone. Do not like to install anything NoSQL with apt-get but it was the only solution I found. – Francis Rodrigues Nov 10 '14 at 22:08
  • Yes, you need to install mongodb with your systems package manager. Also you need to start it (manually). You can only install the mongodb driver with npm (which is already done in a meanjs project). – uwolfer Nov 11 '14 at 10:00
  • Did not quite understand what he said. So for Mean.js I would have to install mongodb via apt-get and the drive in npm? This? – Francis Rodrigues Nov 24 '14 at 17:00
  • But because not only works via npm? And how would I do a job on Linux mongo is installed via npm? Please help me. – Francis Rodrigues Dec 04 '14 at 12:35
  • 1
    mongodb isa system-daemon while npm is a package manager for node stuff. mongodb is not a node module or something like that. For fixing your initial issue, you just need to run your meanjs application on another port (you have tried to run it on the same port as your mongodb should run). – uwolfer Dec 04 '14 at 16:01
  • Thanks @uwolfer! Your help was very helpful for me to understand what I needed to do. – Francis Rodrigues Dec 22 '17 at 17:14
0

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

Community
  • 1
  • 1
oshaiken
  • 2,593
  • 1
  • 15
  • 25
  • Thanks @olzhas-shaikenov, but I need create the person folder to mongodb in my ubuntu server and the mongo.conf is not run correctly this. – Francis Rodrigues Jun 13 '16 at 22:57
  • @FrancisRodrigues From all info you have provide it is not clear if the problem with mongodb configs or it is Ubuntu, sometimes it is bit funky. So I would do this. 1. Go to mongolab and create small sandbox db 2. Connect to your newly created DB, if that works it means that you need to investigate mongod on your local ~$ systemctl status mongod 3. If you are not able to connect to Mongolab, then you need to look at nodejs configs. This way you can separate the issues and find out what really causes the problem. Hope this helps. – oshaiken Jun 14 '16 at 19:16
  • Thank you @oshaiken!! Now I understood what I needed to do. – Francis Rodrigues Dec 22 '17 at 17:15