Mongo database cannot start - ruby

Hello everyone all help is much appreciated. Using MongoDB for the first time, I usually use postgresql. Cannot get any database action, including generating models. Continually get this error:
Mongo::ConnectionFailure: Failed to connect to a master node at localhost:27017
The internet says to try these, none of which work:
1-
sudo rm /var/lib/mongodb/mongod.lock
sudo -u mongodb mongod -f /etc/mongodb.conf --repair
sudo start mongodb
sudo status mongodb
This returns the error that
rm: /var/lib/mongodb/mongod.lock: No such file or directory
2- This is in a file I put in the initialize folder
require 'rubygems'
require 'mongo'
db = Mongo::Connection.new.db("mydb")
db = Mongo::Connection.new("localhost").db("mydb")
db = Mongo::Connection.new("localhost", 27017).db("mydb")
The problem seems to stem from a path, which I have no idea how it works or how to alter it, so if the advice is to alter paths and folders etc. please be very specific. Thank you guys so much.

The mongo daemon has not successfully started.
Usually you do
sudo mongod
Make sure you can connect to the database by typing mongo on the command line which should connect you to the daemon running on 27017.
Then try running your ruby code again.

Related

Error with starting PostgreSQL database on macOS

I am running the latest version of macOS Sierra and I installed PostgreSQL via brew. Then I ran the command:
pg_ctl -D /Users/tmo/PSQL-data -l logfile start
but received for output:
waiting for server to start..../bin/sh: logfile: Permission denied
stopped waiting
pg_ctl: could not start server
Examine the log output.
EDIT: After restarting my operating system and rerunning the command... I'm now receiving a slightly modified output... but the modification is significant.
waiting for server to start.... stopped waiting
pg_ctl: could not start server
Examine the log output.
Where is the "log output" stored?
How do I make this command work?
The problem could be one of two things, that I can see:
A typo in your database path:
/Users/tmo/PSQL-data --> /Users/tmp/PSQL-data
If the above was just a transcription error, I would guess that your postgres user doesn't have write access to the directory where you are setting the logfile. The argument following the -l switch tells PG where to save the logfile. When you don't provide the -l switch with a path, but just a filename, it will use the same dir you use to specify the database cluster (with the -D flag). So in this case, PG is trying to write to /Users/tmp/PSQL-data/logfile, and getting a permission error.
To fix this, I would try:
If the directory /Users/tmp/PSQL-data/ doesn't exist:
sudo mkdir /Users/tmp/PSQL-data
Then create the logfile manually:
sudo touch /Users/tmp/PSQL-data/logfile
Then make the postgres user own the file (I'm assuming user is postgres here)
sudo chown postgres /Users/tmp/PSQL-data/logfile
Try again, and hopefully you can launch the server.
Caveat: I'm not a macOS user, so I'm not sure how the /tmp folder behaves. If it is periodically cleared, you may want to specify a different logfile location, so that you don't need to create and chown the file each time you need to launch the cluster.

mongoexport giving error: could not connect to localhost

I'm keep getting this error when calling mongoexport.
I'm wondering if it is because mongodb is not running locally. I'm very new to mongodb, so if it's the case I'm wondering how to check if mongodb is running on Windows. If it is not the reason, what could it be?
Thanks.
First you need to make sure that mongod is running on your system. Mongo is not set up as a service by default.
In the directory you are in above. You need to type the command mongod <-- not mongodb.... to start the mongo database server. This is assuming you have a data directory set up.. by default mongo will use \data\db but you can specify if you would like
C:\mongodb\bin\mongod.exe --dbpath d:\test\mongodb\data
If you want to set it up as a service, you can find that here :
https://docs.mongodb.org/manual/tutorial/install-mongodb-on-windows/
Finally, what are you trying to export? You are specifying a collection in the code above. You usually call it like this.
mongoexport --db test --collection traffic --out traffic.json
assuming of course you have a collection called traffic.

Yosemite - MAMP - Can't connect to local MySQL server through socket '/Applications/MAMP/tmp/mysql/mysql.sock' (2)

I have problem when I try to connect to MySQL MAMP :
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/Applications/MAMP/tmp/mysql/mysql.sock' (2)
I'm doing research but I have not found a solution to my problem, I try to link mysql.sock like this :
sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock
But, the file /tmp/mysql.sock doesn't exist.
Do you have any ideas ? The problem is blocking me for 2 days, I searched for this time but nothing good for me.
Thanks in advance,
I had the same problem after upgrading MySQL on MAMP from 5.5 to 5.6 version.
After long research I founded this decision https://drupal.stackexchange.com/questions/32402/drush-and-mysql-database-with-mamp-connection-problem
In my case there was no socket file at that location /Applications/MAMP/tmp/mysql/mysql.sock.
The easy solution is to create a symlink:
cd /tmp
ln -s /Applications/MAMP/tmp/mysql/mysql.sock ./mysql.sock
The effect of which is to route all calls for /tmp/mysql.sock to the appropriate MAMP specific path.
simply remove two files ib_logfile0 and ib_logfile1 from /Applications/MAMP/db/mysql56
In some cases /Applications/MAMP/tmp/mysql/mysql.sock.lock may create the problem. remove .lock and it will work (OSX)
I had the same problem. I solved it following these steps:
I stopped and restarted MySQL via System Preferences -> MySQL (see also https://stackoverflow.com/a/26523977/204807)
I entered sudo mysql_upgrade in a terminal window, and pressed enter
After the update process I was able to connect with my MySQL.
Rename .sock file of mysql and restart your MySQL server.
/Applications/MAMP/tmp/mysql/mysql.sock to /Applications/MAMP/tmp/mysql/mysql_old.sock
Also check to make sure MySql is running. You can get this error if you try to use MySql from the command line when MAMP/MySql is not running.
In case this helps anyone, I got past this roadblock by:
Stopping all other versions of MySQL (I forgot that I had Oracle MySQL starting on system launch and I was attempting to connect via that installation.) and removing them anyway to let MAMP handle it.
Use sudo launchctl unload -F /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist
Ensure MAMP is running.
Running /Applications/MAMP/Library/bin/mysql.
1) mysql.server stop
2) /Applications/MAMP/bin/startMysql.sh &&
now on MAMP go to
Tools => Upgrade MySQL databases

Mongodb: Failed to connect to 127.0.0.1:27017, reason: errno:10061

Here is my mongod.cfg file:
bind_ip = 127.0.0.1
dbpath = C:\mongodb\data\db
logpath = C:\mongodb\log\mongo-server.log
verbose=v
Here is my mongod service command:
mongod -f c:\mongodb\mongod.cfg --install
I have installed MongoDB about a week ago and it all worked fine, however today when I ran mongo command I got the following error:
Failed to connect to 127.0.0.1:27017,
reason: errno:10061 No connection could be made because the target machine actively refused it
How can I fix that? I use Windows 8.1
Solution:
I forgot to start mongodb service with this command:
net start mongodb
Improved solution:
1) Change directory to root drive C:\, and type the command below into an admin cmd prompt window,
C:\mongodb\bin\mongod.exe --config c:\mongodb\mongod.cfg --install
2) Then type net start MongoDB after which you should see the following message:
"The Mongo DB service was started successfully"
3) Then go to the control panel Start>Administrative Tools>Services, scroll down to MongoDB in the list of services and change start up type to automatic, if you so desire. Press OK.
4) Finally type C:\mongodb\bin\mongo.exe and you should be connected to the Mongo test DB.
Reference: https://www.youtube.com/watch?v=-mik4dPArCU
This is how I solved it, You can follow step by step here:
MongoDB Steps:
Download the latest 64-bit MSI version of MongoDB for Windows.
Run the installer (.msi file)
Add it to your PATH of environment variables. it Should be from:
C:\Program Files\MongoDB\Server\3.0\bin
now Create a “\data\db” folder in C:/ which is used by mongodb to store all data. You should have this folder:
C:\data\db
Note: This is the default directory location expected by mongoDB,
don’t create anywhere else
.
Finally, open command prompt and type:
>> mongod
You should see it asking for permissions (allow it) and then listen to a port.
After that is done, open another command prompt, leaving the previous one running the server.
Type in the new command prompt
>> mongo
You should see it display the version and connect to a test database.
This proves successful install!=)
Reference link
When you typed in the mongod command, did you also give it a path? This is usually the issue. You don't have to bother with the conf file. simply type
mongod --dbpath="put your path to where you want it to save the working area for your database here!! without these silly quotations marks I may also add!"
example: mongod --dbpath=C:/Users/kyles2/Desktop/DEV/mongodb/data
That is my path and don't forget if on windows to flip the slashes forward if you copied it from the or it won't work!
I was also faced the same issue with mongodb 2.6.
What solved my problem was I just run mongod --repair command
and then start mongod.exe
It's worked for me
just create a folder
C:\data\db
Run below commands in command prompt
C:\Program Files\MongoDB\Server\3.4\bin>mongod
Open another command prompt
C:\Program Files\MongoDB\Server\3.4\bin>mongo
mongodb 2.6.8 on windows7 32bits
you only need create a folder c:/data/db
execute mongod, and execute mongo
Point to your mongodb instalation e.g C:\Program Files\MongoDB\Serve\bin and run mongod.exe so you can open connection to 127.0.0.1:27017.
If it writes that you had not properly shut down or that mongod.lock is not empty
, only delete mongod.lock from C:\data\db\ and it will start.
The problem is that I missed out 'db' folder for the dbpath in the command:
C:\mongodb\bin> mongod --directoryperdb --dbpath C:\mongodb\data\db --logpath C:\mongodb\log\mongodb.log --logappend -rest --install
Under normal conditions, at least 3379 MB of disk space is needed. If you do not have that much space, to lower this requirement;
mongod.exe --smallfiles
This is not the only requirement. But this may be your problem.
What solved my issue was creating a file startmongo.conf that sets the bind_ip to 127.0.0.1 . After that, I just created a *.bat to start the mongo using something like:
mongod --config c:\mongodb\bin\startmongo.conf
When This Error is Coming it is lack of the following
1)Setting the path to mongo db
go to "C" Drive and the installation of Mongo db directory and then go to bin folder in the mongo and copy the path of it
c:/mongodb/server/3.2/bin/ and create a new environmental variable in system properties then name is path and value="c:/mongodb/server/3.2/bin/" here my version is 3.2
2)create a data directory for the data in C Drive
c:/Data/twitter
3)start the server with **
c:/> mongod
check your port config if there is any error as the local port may be assigned to any other
4)start your Mongo database with
Mongo
then your mongo db will start
then in your mongo database
create a database
use DATABASE_NAME
for example:
use twitterdata
switched to db twitterdata
to check your current database
db
twitterdata
to get total databases
show dbs
I started mongod in cmd,It threw error like C:\data\db\ not found.
Created folder then typed mongod
opened another cmd typed mongo it worked.
Here are the steps to solve this issue:
Just go to your MongoDB bin folder and run the mongod.exe file.
Navigate to your mongodb bin folder via Command prompt and start mongo by typing "mongo"
Change file permission to 755 for the file:
/var/lib/mongodb/mongod.lock
first you run the command mongod and check weather the port 27017 has started or not if yes then hit the command mongo....and database will start.
The Port is not open. Thats why the machine refuses communication
Try this, it worked for me.
mongod --storageEngine=mmpav1

install mongoDB (child process failed, exited with error number 100)

I tried to install mongoDB on my macbook air.
I've downloaded zipped file from official website and extract that file and move to root directory.
After that, under that directory, I've made /data/db and /log folder.
Here is my mongodb.config which describes the basic config for my DB.
dbpath = /mongodb/data/db
logpath = /mongodb/log/mongo.log
logappend = true
#bind ip = 127.0.0.1
port = 27017
fork = true
rest = true
verbose = true
#auth = true
#noauth = true
Additionally, I want to know what the # means in the config file.
I put this file to /mongodb/bin, /mongodb is the directory I extracted the files into.
I opened terminal and entered ./mongod --config mongodb.config and I got this back.
Juneyoung-ui-MacBook-Air:bin juneyoungoh$ ./mongod --config mongodb.config
about to fork child process, waiting until server is ready for connections.
forked process: 1775
all output going to: /mongodb/log/mongo.log
ERROR: child process failed, exited with error number 100
How can I handle this error and what this means?
The data folders you created were very likely created with sudo, yes? They are owned by root and are not writable by your normal user. If you are the only user of your macbook, then change the ownership of the directories to you:
sudo chown juneyoungoh /data
sudo chown juneyoungoh /data/db
sudo chown juneyoungoh /data/log
If you plan on installing this on a public machine or somewhere legit, then read more about mongo security practices elsewhere. I'll just get you running on your macbook.
I had a similar issue and it was not related to any 'sudo' problem. I was trying to recover from a kernel panic!
When I look at my data folder I found out a mongod.lock file was there. In my case this page helped a lot: http://docs.mongodb.org/manual/tutorial/recover-data-following-unexpected-shutdown/. As they explain,
if the mongod.lock is not a zero-byte file, then mongod will refuse to start.
I tested this solution in my environment and it works perfectly:
Remove mongod.lock file.
Repair the database: mongod --dbpath /your/db/path --repair
Run mongod: mongod --dbpath /your/db/path
There was the same problem on my machine. In the log file was:
Mon Jul 29 09:57:13.689 [initandlisten] ERROR: Insufficient free space for journal file
Mon Jul 29 09:57:13.689 [initandlisten] Please make at least 3379MB available in /var/mongoexp/rs2/journal or use --smallfiles
It was solved by using mongod --smallfiles. Or if you start mongod with --config option than in a configuration file disable write-ahead journaling by nojournal=true (remove the beginning #). Some more disk space would also solve the above problem.
It's because you probably didn't shutdown mongodb properly and you are not starting mongodb the right way. According your mongodb.config, you have dbpath = /mongodb/data/db - so I assume you created the repository /mongodb/data/db? Let me clarify all the steps.
TO START MONGODB
In your mongodb.config change the dbpath = /mongodb/data/db to dbpath = /data/db. On your terminal create the db repository by typing: mkdir /data/db. Now you have a repository - you can start your mongo.
To start mongo in the background type: mongod --dbpath /data/db --fork --logpath /dev/null.
/data/db is the location of the db.
--fork means you want to start mongo in the background - deamon.
--logpath /dev/null means you don't want to log - you can change that by replacing /dev/null to a path like /var/log/mongo.log
TO SHUTDOWN MONGODB
Connect to your mongo by typing: mongo and then use admin and db.shutdownServer(). Like explain in mongoDB
If this technique doesn't work for some reason you can always kill the process.
Find the mongodb process PID by typing: lsof -i:27017 assuming your mongodb is running on port 27017
Type kill <PID>, replace <PID> by the value you found the previous command.
Similar issue with the same error - I was trying to run the repair script
sudo -u mongodb mongod -f /etc/mongodb.conf --repair
Checked ps aux | grep mongo and see that the daemon was running. Stopped it and then the repair script run without an issue.
Hope that could be helpful for someone else.
I had the same error on linux (Centos) and this worked for me
Remove mongod.lock from the dbpath
$ rm /var/lib/mongo/mongod.lock
Repair the mongod process
$ mongod --repair
Run mongod config
$ mongod --config /etc/mongod.conf
I had the same error. I ran it interactively to see the log.
2014-10-21T10:12:35.418-0400 [initandlisten] ERROR: listen(): bind() failed errno:48 Address already in use for socket: 0.0.0.0:27017
Then I used lsof to find out which process was using my port.
$ lsof -i:27017
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mongod 2106 MYUSERID 10u IPv4 0x635b71ec3b65b4a1 0t0 TCP *:27017 (LISTEN)
It was a mongod that I had forked previously and forgot to turn off (since I hadn't seen it running in my bash window).
Simply killing it by running kill 2106, enabled my process to run without the error 100.
Generally, this error comes when the mongod.conf file is not able to
find a certain path for
Database store
or log store
or maybe processid store
or maybe it's not getting the file permission to access the config directories and files which has been declared in mongod.conf
to resolve this error we need to observe the log generated by the MongoDB
it will clearly indicate whether which file or directory you MongoDB is not able to access
the above error may look like below screenshot
create folder "data" and "db" inside it, in "/" path of your server.
actually you should create or modify permissions of folder that the data is going to be stored!

Resources