How to check if Mongodb is properly installed - mongodb

I installed MongoDb yesterday on a Mac Snow Leopard and got the following error message
Mongo::ConnectionFailure: Failed to connect to a master node at localhost:27017
when trying to run some tests in Rails that used a mongodb.
Another SO question mongo - ruby connection problem about the same error message had an answer that recommended removing the lock file
sudo rm /var/lib/mongodb/mongod.lock
but when I run that command i'm getting
No such file or directory
Any ideas how I can figure out how to get it working or see if it's properly installed?

The easiest way to run mongodb on Mac OS is:
Download binary package from http://www.mongodb.org/downloads, for me, I am using lastest 64 bit version (http://fastdl.mongodb.org/osx/mongodb-osx-x86_64-2.0.2.tgz)
mkdir -p $HOME/opt
cd $HOME/opt
wget http://fastdl.mongodb.org/osx/mongodb-osx-x86_64-2.0.2.tgz to download the latest (2.0.2 for now) 64 bit binary package for Mac OS
tar xf mongodb-osx-x86_64-2.0.2.tgz -C $HOME/opt to unpack the package, and it will be unpacked to $HOME/opt/mongodb-osx-x86_64-2.0.2
mkdir -p $HOME/opt/mongodata to create the data directory for mongodb
$HOME/opt/mongodb-osx-x86_64-2.0.2/bin/mongod --dbpath=$HOME/opt/mongodata --logpath=$HOME/opt/mongod.log to start the mongodb daemon
Then you can run $HOME/opt/mongodb-osx-x86_64-2.0.2/bin/mongo to connect to your local mongodb service
You can also have http://www.mongodb.org/display/DOCS/Quickstart+OS+X as additional reference

It's not running mongod. You need to start it, probably with a script so you can control how it starts. The script I use on my mac looks like: mongod -f /etc/mongodb.conf &.
At this point I can't remember if the install came with /etc/mongodb.conf, or if I put it there myself. It's fairly simple. I store my data/log in my user folder (this is obviously a development environment):
dbpath = /Users/me/data/
logpath = /Users/me/mongo.log
# Only accept local connections
bind_ip = 127.0.0.1
You'll also need to create your data folder, if it doesn't exist.

Related

What means this error in MongoDb running mongodb package for the first time?

$ mongo
BadValue: error: no args for --configdb
try 'C:\Program Files\MongoDB\Server\6.0\bin\mongos.exe --help' for more information
mongod says waiting for connections on port 27017. Whats the problem with mongo?
My path to mongo is: alias mongo="/c/Program\ Files/MongoDB/Server/6.0/bin/mongos.exe"
For everybody with the same problems of MongoDB installiation on Windows accordingly Udemy course of Full stack Bootcamp.
Download current version of Mongodb community server (msi) save it in Program files->Mongodb folder then you should download (https://downloads.mongodb.com/compass/mongodb-mongosh_1.5.1_amd64.deb) MongoDB shell because in 6.0 version or later there is no mongo.exe. save it to Mongodb folder. Save the variables mongod and mongosh via vim or interface tools (.dash_profile). I created via vim. Mongod variable is path to you mongod.exe and mongosh is the path to mongosh.exe. and run the mongod and mongosh in separate terminal tabs. For me it was necessary to rename mongorc.js to mongoshrc.js I used mv mongorc.js mongoshrc.js and that's all. Please be attention if you have old .bash_profile. You need to remove them (rm) because it grabs the first one. Check the list with ls -a.
download the shell from latest version here:
https://www.mongodb.com/try/download/shell?jmp=docs
mongo is change to mongosh, extract the folder in your desire directory, and change your "atlas mongos" path to "mongosh.exe" path. "mongosh.exe" path will be in bin folder of the downloaded zip file.

installing MongoDB to Mac

I need help to solve an error that happened while installing MongoDB into Macbook.
I run this command to kick off installing.
brew install mongosh
ALthough I got a warning msg, it seemed like fine.
I waited so long, and the installation got finally done.
Here is the screenshot of the end.
As you can see, I typed below to check if it was successfully installed.
mongosh --version
1.2.2
Finally I tried to run MongoDB, so typed "mongosh". And I got an error to run it and connect to db called cluster0.
mongosh
Current Mongosh Log ID: 621d2adedeee61396fddb367
Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.2.2
MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017
takeichimasahironoMacBook-Air:~ masa$ mongosh "mongodb+srv://cluster0.8tjjn.mongodb.net/myFirstDatabase" --apiVersion 1 --username mongo
Enter password: *****
Current Mongosh Log ID: 621d2b0f5a5370a82628edcc
Connecting to: mongodb+srv://cluster0.8tjjn.mongodb.net/myFirstDatabase?appName=mongosh+1.2.2
MongoServerSelectionError: read ECONNRESET
Any idea to solve this issue?? Thanks for your effort in advance.
In addition to the good answer above -- On newer versions mac os x the root directory is read only so you will need place your mongo data directory somewhere else, see this thread:
Read-only file system when attempting mkdir /data/db on Mac
I also needed to separately install the mongo command line tool from the cask:
$ brew install mongodb-community-shell
I recommend Homebrew for installing and managing applications on macOS. It is installed using the following command in the macOS terminal. Open up the terminal and paste the command:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
The terminal runs through a series of installation operations, and will probably create folders in your local machine to accommodate Homebrews storage requirements. You can find more detailed instructions here. After it's installed, update the Homebrew dependencies and install MongoDB on the command line:
brew update
brew tap mongodb/brew
brew install mongodb-community
It will take a few seconds. Once it's done, create a directory so MongoDB can store its data.
sudo mkdir -p /data/db
Now to make sure this data directory have the right permissions, you'll run this command:
sudo chown -R `id -un` /data/db
Now our data directory is ready with the right permissions. Next run mongo daemon. Which is a service which runs in the background and listens for connections on a given port. Run this command:
mongod
Now mongo daemon will be running in the background and can be used by your applications. Next, check your MongoDB version:
mongo --version
MongoDB shell version v4.2.6
The command-line results will show the version you have installed on your local machine. I recommend using the latest version of libraries and software whenever possible to avoid compatibility issues with client-side applications.

Stuck in starting meteor

This is really frustrating me. I have a DO VPS with ubuntu 14.04 (64) installed.
I installed VestaCP as control panel on that and have hosted some PHP based personal project.
I also installed meteor on it but never used, now when I am trying to create a project and run it ('meteor create rt' then 'cd rt' then 'meteor')
It is giving the following error :
[[[[[ /home/admin/code/rt ]]]]]
=> Started proxy.
Unexpected mongo exit code 1. Restarting.
Unexpected mongo exit code 1. Restarting.
Unexpected mongo exit code 1. Restarting.
Can't start Mongo server.
root#RD:/home/admin/code/rt#
Could anyone please help? Please ask me for more informations if required.
**** EDIT ****
I created a fresh DigitalOcean server and it is giving the same error on that. Some issue with Digital Ocean? File System of Digital Ocean? I am confused. I am trying it on different flavours of Linux and same result. All are fresh linux installations.
I finally got the solution. Posting it here for others.
This was the problem as a few environment variables which mongodb looks for while starting was not set
Set the variables LC_ALL and LANG and it works fine (mostly setting LC_ALL will do)
first, type locale command and see the output, you will see that it will say something about LC_ALL not set.
Now, add these two lines in /etc/environment and it worked.
LC_ALL=en_US.UTF-8
LANG=en_US.UTF-8
This solution is for Ubuntu 12.04 +
Other variants may require similar work.
Unexpected mongo exit code 1 is still an uncaught exception as far as i think.
You can try by updating your c/c++ compilers uptodate. Have a look here.
It says :
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-4.6
sudo apt-get install g++-4.6
All the best!
So we have narrowed the issue down to meteor's mongo installation on your box (though I think we were pretty sure of this all along). Let's attempt to debug that a bit. The way I have done this in the past is to try to open meteor's mongo with the mongod provided by meteor. You will perform these procedures without running the meteor server. This should give you the warning that is causing Mongo to exit. First you need to find this. In my instance installed on Mint (which should be similar to Ubuntu) it is at:
~/.meteor/packages/meteor-tool/.1.1.3.4sddkj++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/mongodb/bin/mongod
You can look at that location on your Ubuntu box or you can run something like this to get the location:
find ~/.meteor/ -name mongod
Once you find the location then go to the directory of your meteor project you are attempting to run and in that directory you should find this location:
<your meteor project>/.meteor/local
cd into that directory and run the following command:
~/.meteor/packages/meteor-tool/.1.1.3.4sddkj++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/mongodb/bin/mongod --dbpath ./
From there you can analyze the output (or update the question so we can see the output) and this should show you the mongo error you are receiving on startup and allow you to fix it.
I've got the same issues trying to start a meteor app and exactly the mongodb server is being terminated in an unexpectly manner. Generally the virtual linux server from some dealers like the one you mentioned are coming without a swap partition (check in /etc/fstab file) so if you have not enough memory to allocate MongoDB server then meteor app can't be started. You can create a swap partition or instal swapspace
sudo apt-get install swapspace
After that I was able to start the meteor app... Just be patient as swap memory is not as faster as RAM.
Since due some "smart" StackExchange policy I cannot up-vote or comment to working solution...)
Quoted answer works also on Digital Ocean on CentOS 7 x64 vmlinuz-3.10.0-123.8.1.el7.x86_64
first, type locale command and see the output, you will see that it will say something about LC_ALL not set.
Now, add these two lines in /etc/environment and it worked.
I changed the locale setting to match my needs.
Fixed on my Debian 8 with the following bash command, (use sudo if needed)
localedef -i en_US -f UTF-8 en_US.UTF-8

MongoDB not using /etc/mongodb.conf after I changed dbpath

Ever since I changed the dbpath in /etc/mongodb.conf, MongoDB has not been starting automatically, nor using the new dbpath. Prior to the change, MongoDB would be running when the computer started and I was able to simply run the command mongo to get into the console or start my Ruby on Rails server with no issues.
After I made the modification (in order to switch to a new drive with more space), the only way I can get everything to work is by manually running the command mongod --config /etc/mongodb.conf. If I don't run that, it doesn't seem like the service is running and running without the --config option give me the following error: ERROR: dbpath (/data/db/) does not exist. even though the config file says nothing about data/db.
Some other notes:
In addition to changing /etc/mongodb.conf, I moved all files out of /var/lib/mongodb and into /home/nick/appdev/mongodb.
I changed the owner and group from root to nick. Tried changing it back, but it didn't seem to fix anything.
I'm running Ubuntu 12.10 Beta 1 and Mongo 2.2.0 with Ruby on Rails 3.2.8
A late follow up on the above question...
I had a similar issue after moving the db to an ebs on ec2.
It turns out that just running mongod still directs the dbpath to /data/db/ (which exists).
The /etc/mongodb.conf is completely ignored unless specifically directed to.
I manage to work around this by using the directive --config or just the --dbpath(both work)
But was left wondering where does mongod takes it defaults from...?!
I was unable to locate and override these defaults anywhere.
Anyone ?
Note:
I am really annoyed by this behaviour of mongod...This is just bad design,and bad documentation.
It turns out that I needed to set the owner and group to mongodb. When I transferred the files to the new directory, I had set the owner and group to my user account nick and also tried root, neither of which worked.
To do so, here are the following commands:
sudo chown mongodb /home/nick/appdev/mongodb -R
sudo chgrp mongodb /home/nick/appdev/mongodb -R
To confirm that it worked, you can check the file permissions with:
ls -l /home/nick/appdev/mongodb
After checking all permission in the data, journal and log folders as suggested, my problem was solved by giving permission to a lock file in the /tmp folder
sudo chown mongod:mongod mongodb-27017.sock
I was running it as a AWS Amazon Linux instance. I figured that out by executing as the mongod user as below, and then, researching the error code. It might be useful for other troubleshooting.
sudo -S -u mongod mongod -f /etc/mongod.conf
MongoDB 1.6 is very old and the latest production version is 2.2, which contains a large amount of bug fixes and enhancements since 1.6.
Am I correct that you haven't installed 1.6 via a package manager such as yum or aptitude? I don't believe there are packages for 1.6 at present afaik. Therefore, mongod is behaving correctly as you have not started MongoDB with a control script.
Please see this link on configuration file options.

Moved Mongo Database to Different Drive: Unable to acquire lock for lockfilepath

I am in the process of moving my mongo data to a different drive. All of the data I want to move is stored in /data/db and I am moving it to a NAS (Network attached storage).
First step:
mongodump -d mydb -c mycollection -o nas/mongo-temp
This created a file tree in mongo-temp/ like so:
dump
`-- mydb
`-- mycollection.bson
1 directory, 1 file
I then stopped the mongod service and created a new /data/db directory:
/etc/init.d/mongod stop
mkdir mongo-temp/data/db
...and changed the dbpath line in /etc/mongodb.conf
dbpath=.../mongo-temp/data/db
I successfully restarted the mongo server using /etc/init.d/mongod start.
When I try to connect:
mongo
MongoDB shell version: 1.6.4
Thu May 3 09:53:23 *** warning: spider monkey build without utf8 support. consider rebuilding with utf8 support
connecting to: test
Thu May 3 09:53:24 Error: couldn't connect to server 127.0.0.1 (anon):1154
exception: connect failed
I've tried to start mongod with the command mongod --dbpath .../mongo-temp/data/db but I get an error that says:
Thu May 3 09:57:26 exception in initAndListen std::exception: Unable to acquire lock for lockfilepath: /home/dlpstats/nas-mnt/mongo-temp/data/db/mongod.lock
Removing the lockfile doesn't help. If I run the mongod command without --dbpath, the server starts fine and I am able to make queries on my old database.
First, you mentioned that you used mongodump to populate the new drive - was this just a method of backing things up or did you intend that to be the new database files? That is not how it works - mongodump output is not the same as a database file - it needs to be re-imported with mongoresore in fact. If you do a straight data file copy then the transfer will be seamless.
Then, as well as the permissions suggested by Wes in his answer, a few more things to check:
That you have shut down the old server successfully and completely - it's possible it's mis-reported error and you are getting it because it is trying to grab a port that is already open
You are using version 1.6.4 according to the mongo shell output, my guess is that you installed from the Ubuntu repo for 11.04 or similar, that is not a good option - 1.6 is very old at this point. Use the 10gen repos (http://www.mongodb.org/display/DOCS/Ubuntu+and+Debian+packages) or download the binaries and get a more recent version
Last but not least, when you start the mongod manually, make sure all the arguments are the same, like the port. When you connect via the mongo shell, specify the port you started the mongod on - don't rely on defaults when running into issues like this, be explicit.
I faced this problem and issuing following command solved my problem:
rm /var/lib/mongodb/mongod.lock
And then restart the mongod.
But I'm not sure is it a good solution or not.
Check the permissions for the directory and parent directories of mongo-temp. Presumably it's running as the mongodb user?
You need execute permissions on the directory (and parent directories) in order to create files there. Execute permissions on a directory allow you to list the files there, which is needed to be able to open the file for writing.