Starting out with MongoDB - Beginner advice/tools - mongodb

I new to this forum and new to MongoDB.
I am currently taking the 10gen online education course for MongoDB and have been doing some of the online tutorials. However, my programming experience is limited to classroom experience mainly in java with some experience in SQL, python.
As I have been going through the tutorials, I have noticed a gap in knowledge in some key areas and a gap in the tools that I should be using for development. I would like to fill in these gap asap as best as possible.
I am asking for advice on any forums that I should join or look at, websites, software I should be getting (basically any tools that a programmer should have, i am mainly just using eclipse), or just general advice on what you wish you knew when you were starting out..
Thanks!

If you are using Ubuntu:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
sudo nano /etc/apt/sources.list.d/10gen.list
Add the line
deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen
sudo apt-get update
sudo apt-get install mongodb-10gen
sudo nano /etc/mongodb.conf
sudo nano /etc/init.d/mongodb.conf
sudo service mongodb start
mongo
> db.test.save( { a: 1 } )
> db.test.find()
sudo apt-get install php-pear
sudo apt-get install php5-dev
sudo apt-get install make
wget https://github.com/mongodb/mongo-php-driver/archive/master.zip
unzip master.zip
phpize
./configure
make
sudo make install
or
sudo pecl install mongo
cp /usr/lib/php5/20090626+lfs/mongo.so /opt/lampp/lib/php/extensions/no-debug-non-zts-20090626/mongo.so
cp /lampp/lib/php/extensions/no-debug-non-zts-20100525
sudo /opt/lampp/lampp restart
If you are using Windows:
Download
Mongodb
http://www.mongodb.org/downloads
and
mongodb-php driver
https://github.com/mongodb/mongo-php-driver/downloads
You may also need RockMongo (similar to phpmyadmin)
http://rockmongo.com/downloads

Related

Unable to install mongodb properly on ubuntu 18.04 LTS

I am trying to install mongodb on my Ubuntu 18.04 LTS, but it has the following error saying
You might want to run 'apt --fix-broken install' to correct these. The
following packages have unmet dependencies: mongodb-org : Depends:
mongodb-org-server but it is not going to be installed
Depends: mongodb-org-mongos but it is not going to be installed
Depends: mongodb-org-tools but it is not going to be installed E: Unmet dependencies. Try 'apt --fix-broken install' with
no packages (or specify a solution).
umar#umar-Lenovo-ideapad-320-15ISK:~/Desktop/portfolio/async-demo$
sudo apt-get install -y mongodb
I beleieve the reason behind this is already mentioned on their website, clearly saying
PLATFORM SUPPORT
MongoDB only provides packages for 64-bit LTS (long-term support)
Ubuntu releases; for example, 14.04 LTS (trusty) and 16.04 LTS
(xenial). See Supported Platforms for more information.
These packages may work with other Ubuntu releases; however, they are
not supported.
So how can I install mongodb on my latest Ubuntu 18.04 LTS?
For sake of clarity, I am listing the things I did to correct the errors:
I followed their official website to install mongodb
1. sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4
2. echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list
3. sudo apt-get update
4. sudo apt-get install -y mongodb-org
Now here I got errors saying: You might want to run 'apt --fix-broken
install' to correct these. The following packages have unmet
dependencies:
I tried,
apt --fix-broken install
It did not work, somewhere I got clue to run
sudo apt -f install
It also returned error.
Errors were encountered while processing:
/var/cache/apt/archives/mongodb-org-server_4.0.0_amd64.deb
/var/cache/apt/archives/mongodb-org-mongos_4.0.0_amd64.deb
/var/cache/apt/archives/mongodb-org-tools_4.0.0_amd64.deb E:
Sub-process /usr/bin/dpkg returned an error code (1)
I believe the main problem is compatability with version. So basically I have Ubuntu 18.04, how I install mongodb on this version, so that I can work without any trouble.
You need to first uninstall the mongodb, you can use:
sudo apt-get purge mongodb-org*
After this, install mongodb through the following commands:
sudo apt-get install mongodb
And then update:
sudo apt-get update
You are done with the installation of mongodb. You can check it by using the below command:
mongo --version
EDIT: It's been a number of years, and unfortunately the top answer still points users away from the latest stable version of MongoDB. In fact the last available package for mongodb is 3.6.3.
I don't work at the company anymore, but I will point to:
https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-ubuntu/
That's the best way to install the latest stable version MongoDB. It includes instructions for adding the necessary repositories and keys to allow running apt install mongodb-org. There is a platform support matrix that will help with identifying which versions of MongoDB you can install on any given Linux OS version.
just want to chime in here. I'm the Senior Technical Writer for MongoDB Server Docs. This post is one of a few that comes up with "install MongoDB on Ubuntu 18.04", and there are several comments here referencing the mongodb package for installation. The unofficial mongodb package provided by Ubuntu is not maintained by MongoDB. You should always use the official MongoDB mongodb-org packages. Furthermore, from a bit of personal testing it looks like having mongodb installed will cause issues if you try to install mongodb-org, so its just added trouble
The few times I've run into this issue when testing locally, attempting to install one of the subpackages (i.e. mongodb-org-server) usually surfaced the actual error (i.e. missing libcurl3, which was removed in 18.04 as a default installed library). These issues may be more common when testing development builds ( at the time of writing, that's the 4.2 dev series).
To check which package you have installed on your local system, run the following:
sudo apt list --installed | grep mongo
This was my output after I installed mongodb, then attempted mongodb-org:
mongo-tools/bionic,now 3.6.3-0ubuntu1 amd64 [installed,auto-removable]
mongodb-org/bionic,now 4.0.5 amd64 [installed]
mongodb-org-shell/bionic,now 4.0.5 amd64 [installed,automatic]
mongodb-server-core/bionic,now 1:3.6.3-0ubuntu1 amd64 [installed,auto-removable]
So you can see, I've got a mix between the two packages (and a bunch of dkpg errors). I ended up using a mix of apt remove , apt autoremove, and apt purge to fix up the system.
Based on this excellent Answer:
https://stackoverflow.com/a/51421152/659354
And this Page:
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/
The commands I used to install MongoDB 4.2
sudo apt-get purge mongo* - Note: mongo to remove the client as well as the server.
sudo apt-get install mongodb-org - Note: install command run after the Mongodb.org Source was added to the Apt-get sources list.
This is because as of now Mongo DB for Ubuntu 18.04 is only available as a development version (See: MongoDB Distros).
I just installed it by doing the following:
Add the corresponding signature:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4B7C549A058F8B6B
Add the supported version:
echo "deb [arch=amd64] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/development multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list
Update:
sudo apt update
Install:
sudo apt install mongodb-org-unstable
If you get a "GPG error" repeat step 1 with the key that is shown in the error message. You might be able to install via
sudo apt install mongodb
but according to MongoDB this is not supported and will most probably not install the newest version.
The easiest way to install MongoDB and use the mongod command on ubuntu 18.04.
Update the packages list.
$ sudo apt update
Install the MongoDB.
$ sudo apt install -y mongodb
Check the service's status.
$ sudo systemctl status mongodb
3a. You should see
● mongodb.service - An object/document-oriented database
Loaded: loaded (/lib/systemd/system/mongodb.service; enabled; vendor
preset:enabled)
Active: active (running) since Sat 2019-03-11 10:45:01 UTC; 4min 13s ago
Docs: man:mongod(1)
Main PID: 2312 (mongod)
Tasks: 23 (limit: 1153)
CGroup: /system.slice/mongodb.service
└─2312 /usr/bin/mongod --unixSocketPrefix=/run/mongodb --config
/etc/mongodb.conf
To allow access to MongoDB on its default port 27017
$ sudo ufw allow 27017
Check status
$ sudo ufw status
5a. You should see
Status: active
To Action From
-- ------ ----
27017 ALLOW Anywhere
27017 (v6) ALLOW Anywhere (v6)
5b. If it returns inactive
$ sudo ufw enable
Output:
Firewall is active and enabled on system startup.
Check the / directory to see if there is a data/db directory, if not:
$ sudo mkdir -p /data/db
To run the mongod first you need stop mongodb:
$ sudo systemctl stop mongodb
Finally, you can run the mongod:
$ sudo mongod
cd /etc/apt/sources.list.d
remove files related to mongodb
sudo apt update
This solved it for me.
Uninstall and remove any Mongo packages.
$ sudo apt-get purge mongodb-org*
Check if related directories removed
$ sudo rm -r /var/log/mongodb
$ sudo rm -r /var/lib/mongodb
Recheck for autoremove any remaining mongo packages
$ sudo apt-get autoremove
Configure your directory
$ sudo dpkg --configure -a
Force install anything required
$ sudo apt-get install -f
Install from official site: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/
Finally restart your Ubuntu and check status of Mogodb server as you did earlier.
If you need to install mongodb binary (Manually) to your Ubuntu 18.04 LTS (Bionic). You need to download mongodb .tgz file from this link .
1) Download it to your ~/Downloads folder and moveit to home directory by typing mv Downloads/mongodb-linux-x86_64-ubuntu1804-4.0.4.tgz ~/
2) Then unter it by typing tar -zxvf mongodb-linux-x86_64-ubuntu1804-4.0.4.tgz place it here (Home directory /home/). Dont move it from here.
3) Then make a directory at /data/db location and give write permission to thatdirectory.
sudo mkdir -p /data/db
sudo chmod -R 777 /data/db
4) Now, this is the tricky area. Make sure u r in hme directory by typing pwd (Present Working Directory)
pwd
it will show
/home/<your user name>
Then type
ls -al
This command will show up all hiddenfile at home directory and search for
~/.bashrc
5) Edit the .bashrc file and write
export PATH=mongodb-linux-x86_64-ubuntu1804-4.0.4/bin:$PATH
and save the file type source ./bashrc
Then type echo $PATH at terminal it will display ~/mongodb-linux-x86_64-ubuntu1804-4.0.4/bin:/home/xenon/.nvm/versions/node/v10.15.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
6) Now at terminal type mongo --nodb
it will show MongoDB shell version v4.0.4
From here , you are all set, go ahead and enjoy mongodb installation. This istallation is bit complex but by this method you can easily control the version of mongodb and use it as per your need.
7) Then start mongod
>sudo mkdir -p /var/log && sudo chmod -R 777 /var/log
>mongod --port 27017 --dbpath /data/db --logpath /var/log/local.log --fork
>mongo --port 27017
I had the same problem, and for me the solution was purge, but with the (*) . Purge everything, so i did this:
sudo apt-get purge mongo-tools*
sudo apt-get purge mongodb*
then i follow the steps from the documentation. (Actual version is 4.2.2), and the installation was in Ubuntu 18.04. (URL: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/)
wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add -
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list
sudo apt-get update
sudo apt-get install -y mongodb-org
With that four steps from the documentation i finally install mongodb community edition on Ubuntu. My problem was 3 files,that can't process.
mongodb-org-server
mongodb-org-mongos
mongodb-org-tools
I hope its help someone
run sudo apt autoremove and re-install mongodb .
For Ubuntu version 18.04 LTS, it's better if you will install MongoDB manually.
I need to go through the following steps to make it run on my Ubuntu 18.04:
Fallow manual installation steps from the following mongo DB manual
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu-tarball/
Download .tgz with the following configurations
Download MongoDB
Please note, when you install MongoDB 3.6 or above, it comes up with Curl library of "libcurl4" version and which has some compatibility issues on ubuntu 18.04
Due to this, you will end up resulting following output when try to execute "mongod" command:
mongod: /usr/lib/x86_64-linux-gnu/libcurl.so.4: version
`CURL_OPENSSL_3' not found (required by mongod)
To fix this problem, you need to uninstall "libcurl4" dependent library by using the following command
sudo apt-get remove libcurl4
Then need to install back lower curl lib version (i.e. "libcurl3"), as mongo expects it on ubuntu version "18.04"
sudo apt-get install libcurl3
You may need to use "sudo" to fork the data and log directories with the installation if it fails with the manual steps
sudo mongod --dbpath /var/lib/mongo --logpath /var/log/mongodb/mongod.log --fork
you can run "mongo" command now to see the mongo shell running.
It works for me.
I was facing a libssl1.1 issue when trying to install mongo-db in Pop!_OS 22.04 LTS (or Ubuntu 22.04 LTS).
Go to http://archive.ubuntu.com/ubuntu/pool/main/o/openssl
Find the exact version of libssl for example libssl1.1.1
wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1-1ubuntu2.1~18.04.20_amd64.deb
Then install
sudo dpkg -i libssl1.1_1.1.1-1ubuntu2.1~18.04.20_amd64.deb
Hope this helps others who are trying to do the same.
The issue is referenced in https://github.com/dotnet/sdk/issues/24759.
All credit goes to #feisalramar.
Just run the command sudo apt install mongodb it will install the mongodb, because mongodb is now part of ubuntu repository. After installation run command sudo service mongodb start to start the mongodb server. Then if you run command mongo it will give you shell helper. To see the existing database use command show dbs. After successfull installation you will find there pre existing database names are admin, config, local. Use command db to see which database is currently running on server, there will a database named test or somthing. To add a collection (tables on SQL DB) just use the insert command with an initial document (row in SQL DB) information db.data.insert({"username":"Brad Pitt"})
In previous command data is my collection name.
Now to see all documents in data collection just use command db.data.find();
Other commands:
sudo service mongod status, sudo service mongodb stop, sudo service mongod restart ,sudo service mongod stop.
For more information, you can visit https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/
;
For me on Pop_OS Linux 20.04 LTS helped:
$ sudo apt-get purge mongodb*
Then creating /etc/apt/sources.list.d/mongodb-org-4.4.list file for Ubuntu 18.04 (Bionic) via this command:
$ echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
instead of Ubuntu 20.04 (Focal)
After that install mongodb-org:
$ sudo apt-get update
$ sudo apt-get install -y mongodb-org
And start mongodb service:
$ sudo systemctl start mongod
This issue is only on Ubuntu 22.04,
Try this out:
echo "deb http://security.ubuntu.com/ubuntu impish-security main" | sudo tee /etc/apt/sources.list.d/impish-security.list
sudo apt-get update
sudo apt-get install libssl1.1
Try this, I successfully find this out
$ sudo apt-get install -y mongodb

How to delete an old version of mongodb and install the new one in cloud9 IDE?

I'm using the cloud9 IDE and I'm trying to connect through the mongo shell to a mongodb instance running on mongolab. Mongolab now runs mongodb version 3.0 but cloud9 has version 2.6 installed.
I've tried following the instructions on the mongodb website for installing on ubuntu 14.04 using the mongodb binaries, and although all of the commands it instructed me to use were executed without errors, I didn't understand exactly what was happening, and when I checked the mongodb version with mongod --version it still said I was running the old version - 2.6.10
Can someone explain the steps to uninstall the old version and install the new version of mongodb in cloud9?
The first thing you have to do is to remove the existing mongodb:
sudo apt-get remove mongodb* --purge
Then we can follow instructions from MongoDB docs.
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
sudo apt-get update
sudo apt-get install -y mongodb-org
I hope this helps.

MongoDB - Ubuntu 15.04 missing packages

I've updated my Ubuntu 14.04 to the latest 15.04. Since then Mongo failed to run. can run the command mongo and it'll advise the version and so on but server will not run: sudo service mongod start as normal.
When I ran: sudo apt-get install -y mongodb-org it failed with the error in the screen shot below:
I completely purged mongo and re-installed, followed the instructions from here. However when I ran sudo apt-get update I noticed the below packages were 404'ing. See Screen shot below.
If anyone could shed any light on this would be great?
Following instructions from this page page http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/
but with slighty changed second step 2. Create a list file for MongoDB:
echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
I put trusty (code name for Ubuntu 14.04 LTS) instead of $(lsb_release -sc) which issues vivid as codename for 15.04
I see now that #Nail Lonergan already commented echo path change...
There is currently no build available for Ubuntu 15.04. Check this page for all builds: https://www.mongodb.org/downloads#development
After having heaps of issues, finally this is how I installed it,
Ubuntu 15.04
apt-get update
apt-get dist-upgrade
apt-get install -y mongodb
sudo apt-get install upstart-sysv
sudo service mongodb status
if not running
sudo service mongodb start
Install PHP Driver
sudo apt-get install php5-dev
sudo apt-get install build-essential
sudo pecl install mongo
https://sonnguyen.ws/install-mongodb-mongo-php-in-ubuntu/
sudo apt-get install mongodb
ps -ef|grep mongo
sudo pecl install mongo
sudo apt-get install php5-dev php5-cli php-pear

Unable to locate package mongodb-org on Debian

I'm trying to install MongoDB 3.0 on my Debian server (wheezy) 32 bit and I can't figure out what's gone wrong despite the fact that I followed the MongoDB install Tutorial:
apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
echo "deb http://repo.mongodb.org/apt/debian "$(lsb_release -sc)"/mongodb-org/3.0 main" | tee /etc/apt/sources.list.d/mongodb-org-3.0.list
apt-get update
apt-get install -y mongodb-org
The fourth command still failing even if the others are successful:
E: Unable to locate package mongodb-org
I've found subjects of this matter on Stackoverflow but it was on Ubuntu so, ...
EDIT:
lsb_release -sc gives wheezy
NO APT-GET SOLUTION:
Get the Linux 32-bit Legacy version of MongoDB here:
wget https://fastdl.mongodb.org/linux/mongodb-linux-i686-3.0.2.tgz
tar zxvf mongodb-linux-i686-3.0.2.tgz
cp mongodb-linux-i686-3.0.2.tgz/bin/* /usr/bin
Don't forget to change ownership/permissions.
sudo apt-get install -y mongodb
I spent 2 hrs on the same problem on clean Debian x64. just try. this.
As you can verify by visiting
http://repo.mongodb.org/apt/debian/dists/wheezy/mongodb-org/3.0/main/binary-i386/
there are no packages there, in contrast to
http://repo.mongodb.org/apt/debian/dists/wheezy/mongodb-org/3.0/main/binary-amd64/
I do not know why this is the case, but one option is to build the packages from source in your i386 machine.
I litle late but:
wget http://repo.mongodb.org/apt/debian/dists/wheezy/mongodb-org/3.4/main/binary-amd64/{package_vesion}
sudo dpkg -i {package_version}
But I could not found the x86 version, only x86_64.
I used a normal root command apt-get install mongodb-org without the -y option
P.S: that works for Debian 9 too

Trying to setup Mongodb on Debian

I am trying to setup the database client MongoDB and am running into some problems getting it to startup.
What I have done:
I downloaded the 2.0 version of mongoDB from http://fastdl.mongodb.org/linux/mongodb-linux-i686-2.0.0.tgz
I extracted it (tar xzf).
I then ran the command mkdir /data/db
Unfortunately when I try to run mongod I get command not found. Any reason why I might be failing at this part of the process?
I think you did not scroll all the way down on the download page and took the first linux version that was there. Here is the link that will help you install mongodb from APT it works really well. http://www.mongodb.org/display/DOCS/Ubuntu+and+Debian+packages
Just untaring an archive doesn't install it.. You have to go to the mongodb directory and run ./bin/mongod to run the server..
Try this:
# apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
# echo 'deb http://downloads-distro.mongodb.org/repo/debian-sysvinit dist 10gen' | tee /etc/apt/sources.list.d/mongodb.list
# apt-get update
# apt-get install -y mongodb-org
To start MongoDB:
# /etc/init.d/mongod start
There is a debian package for mongodb. so just run apt-get install mongodb in terminal.
An easy way to install and configure MongoDB on Debian is from the APT package, check out the official docs for Ubuntu and Debian packages for step-by-step instructions.
I know I'm a bit late to the party as an answer has been checked but I generally don't like doing the packages route because I've had bad luck with out of date ones in the past. However, I just hit this issue myself after unzipping and it turned out to be a permissions issue from when I initially did the tar xzf.
When in the bin folder I was getting this:
$ mongod
-sh: mongod: not found
What I wound up doing was this:
sudo chown -R $USERNAME:$USERNAME /mongodb-linux-x86_64-2.0.0/bin
sudo chown -R $USERNAME:$USERNAME /data/db
cd mongodb-linux-x86_64-2.0.0
sudo bin/mongod
and VOILA!
Wed Oct 5 22:46:59 [initandlisten] MongoDB starting : pid=3049 port=27017
dbpath=/data/db/ 64-bit host=MyRackspaceRandomProject
Wed Oct 5 22:46:59 [initandlisten] db version v2.0.0, pdfile version 4.5
Hopefully this helps a little more.
If version 2.0 of Mongodb is sufficient, the easiest way to install it on Debian squeeze is by:
$ sudo echo "deb http://backports.debian.org/debian-backports squeeze-backports main" >> /etc/apt/sources.list
$ sudo apt-get update
$ sudo apt-get -t squeeze-backports install mongodb mongodb-clients mongodb-dev mongodb-server
It's important (in this case) explicitly to include mongodb's dependency packages as shown above, or you may experience mysterious behavior from the mongodb server—more information here.