MongoDB installation on aws ec2 server - mongodb

I am trying to install mongoDB on ec2 ubuntu server and following this link
https://optimalbi.com/blog/2017/09/14/how-to-install-mongodb-with-aws-ec2/
but it gives me this error
root#ip-172-31-9-20:~# sudo apt update
E: Malformed entry 1 in list file /etc/apt/sources.list.d/mongodb-org-3.4.list (Component)
E: The list of sources could not be read.
I tried
sudo sed -i -e '1d' /etc/apt/sources.list.d/mongodb-org-3.4.list
But then it gave the following error -
E: Type '“deb' is not known on line 1 in source list /etc/apt/sources.list.d/mongodb-org-3.6.list
E: The list of sources could not be read.
Any help would be appreciated.

If your ubuntu version is 18.04, you need to put a different syntax there. You need to delete the previous file.
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list
Then you can do sudo apt update

Related

mongodb is not running on my Ubuntu 20.04.3 LTS

I'm trying to follow a MongoDB example for learning matters.
The instructions say that after starting MongoDB I will have a mongodb terminal so I can create a database and make it the active one.
The problem is that I start mongodb but I don't have the application terminal, it runs but at the end I have the ubuntu's terminal.
I followed this https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/ to install Mongo:
pip install pymongo
wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list
sudo apt-get update
sudo apt-get install -y mongodb-org
I also installed COMPASS, this is running correctly
wget https://downloads.mongodb.com/compass/mongodb-compass_1.26.1_amd64.deb
sudo dpkg -i mongodb-compass_1.26.1_amd64.deb
mongodb-compass
I'm starting Mongo
sudo systemctl start mongod #this do something but takes me back to the terminal prompt.
mongosh #is launching this "MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017"
Definitely I'm doing something wrong but I cannot identify it.
Does anyone have an idea?
Thanks in advance

MongoDB is not installed correctly in Ubuntu 18.04 server

Specs: Ubuntu 18.04 Nginx server, Vestacp control panel.
MongoDB was pre-installed in my server, in 3.6.3 version. It was working but I wanted to upgrade it to version 4.4 (current release).
The problem now is that I can't start the mongo service (community edition).
Steps I followed so far:
Stop MongoDB service, Remove packages and remove Data Directories.
sudo service mongod stop
sudo apt-get purge mongodb-org*
sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongodb
Trying to install the new version 4.4 the exact steps from the documentation. Below are the commands with an order:
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
sudo apt-get install gnupg
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
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
sudo apt-get update
sudo apt-get install -y mongodb-org
echo "mongodb-org hold" | sudo dpkg --set-selections
echo "mongodb-org-server hold" | sudo dpkg --set-selections
echo "mongodb-org-shell hold" | sudo dpkg --set-selections
echo "mongodb-org-mongos hold" | sudo dpkg --set-selections
echo "mongodb-org-tools hold" | sudo dpkg --set-selections
ps --no-headers -o comm 1
sudo systemctl start mongod
sudo systemctl daemon-reload
sudo systemctl enable mongod
mongo
Errors:
sudo apt-get update
It throws an error:
Skipping acquire of configured file 'nginx/binary-i386/Packages' as repository 'http://nginx.org/packages/mainline/ubuntu bionic InRelease' doesn't support architecture 'i386'
On the step:
sudo apt-get install -y mongodb-org
E: Sub-process /usr/bin/dpkg returned an error code (1)
On the step:
sudo systemctl start mongod
Failed to start mongod.service: Unit mongod.service not found.
Directories:
/var/lib/mongodb
and
/var/log/mongodb
are not auto-created after the installation and I can't find them on the above paths.
The port I am trying to begin the server is the default 27017 and I set the rules to ufw.
I am tried to find a solution from similar posts but nothing. I'm stuck for two days now.
Any thought or help?
The problem was in uninstallation of previous MongoDB version 3.6.3.
The command in terminal...
sudo apt-get purge mongodb-org*
...Doesn't uninstall all the packages correctly.
The correct uninstallation was to type in the command line:
sudo apt list --installed | grep mongo
...In order to see if there are any packages left from MongoDB. I had 2 packages left that "purge mongodb-org*" couldn't delete.
So the correct removing executions are the below:
sudo apt remove mongodb
sudo apt purge mongodb
sudo apt autoremove
After that, the installation of the new MongoDB version 4.4 was successfully completed without errors!

Malformed entry 1 in list file /etc/apt/sources.list.d/MongoDB.list (Suite)

I was trying to install MongoDb on Ubuntu 17.10 but i couldnt or there were some errors so I decided uninstall everything and reinstall fresh. So i did some purge commands that i found on the net and after doing that now if I do: sudo apt update
i get the following messages
sudo apt update
E: Malformed entry 1 in list file /etc/apt/sources.list.d/MongoDB.list
(Suite)
E: Malformed entry 1 in list file /etc/apt/sources.list.d/mongodb.list
(Suite)
E: The list of sources could not be read.
In this case, as you dont have a specific line wrong in the file, better delete the file MongoDB.list and add again the respective PPA.
Try:
sudo rm /etc/apt/sources.list.d/MongoDb.list
Add again the PPA from MongoDb. Now is time to update by running.
sudo apt-get update
Try running following command
sudo sed -i -e '1d' /etc/apt/sources.list.d/mongodb-org-3.4.list
This would produce following error
E: Type '“deb' is not known on line 1 in source list /etc/apt/sources.list.d/mongodb-org-3.6.list
E: The list of sources could not be read.
Now to fix this, go to /etc/apt/sources.list.d and then open it with
nano mongodb-org-3.4.list
And here remove the double quotes (")
Try running sudo apt-get update now. Hopefully it will work.

command not found: mongoexport

I use a mongodb database, I am on macOS, the command mongoexport does not pass, I am under the /bin directory of the database
here is my command
mongoexport --db Battleship --collection user --out resultExport.json
my database is Battleship , and the collection is user
any idea \?
If mongoexport is in the same directory that your current one (and also is executable and you got perms to execute it) then you need to prepend executable with ./ and invoke it that way:
./mongoexport --db Battleship --collection user --out resultExport.json
Here's more on why you need that for https://askubuntu.com/a/320657/649099
If there is a warning mongoexport command not found, you have to install
mongodb-org-tools
For centos users
yum install mongodb-org-tools
For Ubuntu:
Import the public key used by the package management system.
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
Create a list file for MongoDB
Ubuntu 18.04:
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
Ubuntu 20.04:
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
Reload local package database.
sudo apt-get update
Install the MongoDB packages.
sudo apt-get install -y mongodb-org

Getting error status:unknown job while starting MongoDB using Ubuntu

I am not able to start MongoDB in my Ubuntu machine. First I follow below steps to install MongoDB in my Ubuntu system.
1->sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
2-> echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
3-> sudo apt-get update
4-> sudo apt-get install -y mongodb-org
5-> service mongod start
While I tried to start the MongoDB I got the following message rather than its starting.
status:unknown job : mongod
I am trying to also remove the mongodb.lock file from /var/lib/mongodb folder but unable to remove here I need to start the MongoDB service.
ok try this one:
sudo apt-get purge mongodb-stable
sudo apt-get install mongodb-stable
(remove the lock file if present in /var/lib/mongodb)
Then edit /etc/init/mongodb.conf removing the line "limit nofile 20000"