Change default MongoDB port on Ubuntu Snap installation - mongodb

I have installed MongoDB using using the following command using snap package manager.
snap install mongo32;
It's working fine. However, I want to change the port & I couldn't find mongodb.conf for this installation. I searched for it in the following locations:
/snap/mongo32
/etc
Recursive grep search gave me the file which contains default port number(32017) for this installation in this file:
/snap/mongo32/2/command-mongod.wrapper
However, this file is read-only, and I assume that it is not a good idea to make changes to a read-only file. Please advice how should I change the default port for mongo32 snap installation. Thanks.

You can see in the snapcraft manifest file here that the default port number is hardcoded:
mongod:
command: bin/run.sh mongod --port=32017 --smallfiles --noprealloc
The mongo snaps follow the convention mongoNN where NN is the port number NN017 (e.g. mongo33 will use the port 33017)

Related

MongoDB "Automatically disabling TLS 1.0, to force-enable TLS 1.0"

I'm following this (https://codingthesmartway.com/the-mern-stack-tutorial-building-a-react-crud-application-from-start-to-finish-part-2/) tutorial, and when I reach the part when I type "mongod" into the terminal, I end up with this holy hot mess in my command line. What's gone wrong?
If you do not specify a location for the data files, MongoDB will store its data by default in the \data\db folder of the current drive C:. If the folder does not exist, it will fail with this error. Either create the C:\data\db folder or specify a different location for the data files with the --dbpath option.
The TLS 1.0 disabled warning is not causing any issues. It is just notifying you that TLS 1.0 is disabled by default (TLS 1.0 is considered insecure for encrypted connections), so by default MongoDB only supports TLS 1.1 and newer. This is important only if you're enabling SSL connections to your database.
After installing MongoDB, setup the environment variable of mongodb.
or make a data/db in your C: drive.
if all these are not woking then install mongodb compass and follow the below steps:
1# In start menu type services and open it
2# look for mongodb and start it manually
3# now to check mongod server is running or not go to c:/prografiles/mongodb/4.4/bin/ (where you install your mongodb compass) and open terminal and type mongo > show dbs command show all the databases.
images links for better understanding:
https://drive.google.com/drive/folders/1CLwjXCZ8q6JKwfBXZT9byC_KHmtAjP6E?usp=sharing
I had the same issue with my Ubuntu machine. I found the solution by restarting the MongoDB; use the following commands to restart:-
sudo systemctl stop mongod
sudo systemctl restart mongod
You can also check it in How to install MongoDB on Ubuntu
c:\data\db\ is not found so create it .the same error occurred in my terminal and it was saying that E:\data\db\ is not found and then I created it in my E drive and the problem got solved.
same huge mess for me,
this command will help.
./mongod.exe --config ./mongod.cfg --auth
try to run mongodb with parameter --dbpath /usr/local/mongodb-data if you using mac m1

why does mongodb not care what my config file is?

I can tell mongod does not respect its own default config file because when I type 'mongod' in the terminal, i see
MongoDB starting : ... dbpath=/data/db ...
however in my /etc/mongodb.conf i have
storage:
dbPath: /home/ubuntu/data/db
So it appears mongod does not care about what is defined in its own default config file?
(i know i can add --config /etc/mongodb.conf but I don't see why if this config file is by definition the default config file)
Second question, if mongod does not use /etc/mongodb.conf - is there another config somewhere telling it to put the database path do /data/db (so i can change it) - or is /data/db hard-coded in the int main() of the mongod.exe
Third question: if so does this basically mean you have to always specify the path of the config file when starting mongo?
Fourth question: If it is the case that i must manually define the path to the mongodb config file when starting mongo, how would it be possible to both start mongo as a service like:
service start mongodb
and also specify the config file to be used for the service?
ps. i already know about mongod --fork .... but i'm trying to avoid big long inputs and just have a simple server start/stop/status function with one config file that is respected.
thanks
i'm trying to avoid big long inputs and just have a simple server start/stop/status function with one config file that is respected.
If you run MongoDB as an service in Ubuntu, the config path of /etc/mongod.conf is included in the service definition. Starting and stopping MongoDB as a service is the recommended way to run with consistent settings using a standard config location. You do not need to include any extra parameters when starting or stopping the service; any parameters should be set via the config file.
in my /etc/mongodb.conf i have
Note that the expected location is usually /etc/mongod.conf (named to match the corresponding server daemon). An /etc/mongod.conf with defaults for your O/S should be created as part of the installation (assuming you are using packages provided by MongoDB).
If you installed packages from an alternative source such as the Ubuntu Universe repository, it is possible that your service definition is using /etc/mongodb.conf and may have different defaults from the MongoDB documentation.
So it appears mongod does not care about what is defined in its own default config file?
If you start mongod from the command line, default values for mongod options are used. As at MongoDB 4.0 there is no default config file path baked into the server binary, but there is a default dbPath (/data/db on Linux).
There's a relevant feature suggestion you can watch/upvote in the MongoDB Jira issue tracker: SERVER-36150: Improved default config file handling.

Need to launch mongod using launchctl

I have installed MongoDB using manual option.
When I fire mongod it will take parameters from somewhere else specially for dbPath.
I want to have my own dbPath without specifying it with --dbPath each time.
So I found option to provide mongod.conf file and call mongod --config option but still I need to pass path of .conf file.
My ultimate goal is to just launch mongod as service and it will read config file from path I configured. For this I tried LaunchAgent and LaunchDaemon with no luck. What I thought is that if I can configure LaunchAgent or Daemon then I will provide path to mongod of bin directory of MongoDB folder and provide --config and path for .conf file as argument and then I need to just launch mongod using launchctl with name mongod and it will start mongod --config <.conf file path>.
But I am not able to do so. I read nearly 15-16 posts on LaunchAgent and Daemon but did not get solution my problem. I tried to do so with making mongod.plist file at various places like /Library/LaunchDaemon, /Library/LaunchAgent and ~/Library/LaunchDaemon but I always get error "Path had bad ownership/permissions". I tried chown and chgrp but no luck.
I hope you got my point. I really need complete solution to achieve my goal.
Do you use linux or windows?
This is the default location of mongodb.conf in linux:
/etc/mongodb.conf
You can simply edit it with your parameters, and start the service using:
sudo service mongodb restart
If you are using windows, it depends on the version of MongoDB you are using, but check in:
C:\Program Files\MongoDB\Server\3.4\...
For the same file.

how do I edit the Mondodb.conf file

How do I edit the mongodb.conf file?
I want to change the bind_ip from 127.0.0.1 to 0.0.0.0.
I have tried sudo mongod --bind_ip 0.0.0.0
I have tried manually editing the file (in a text editor), but it won't let me save.
I have tried changing the permissions of the file, yet I still can not save.
I didn't create a mongodb.conf file either, so I'm not sure why it was automatically set up as 127.0.0.1
I'm using Ubuntu.
I've tried searching around but I haven't had any luck.
All suggestions will be much appreciated.
Both the /etc/mongod.conf and /var/log/mongodb/mongob.log files are write restricted to super users. Your standard login account is not allowed to directly modify them.
To edit the mongod.conf file , open a terminal and run the following command (sudo will ask you for your password):
gksudo gedit /etc/mongod.conf
Edit the file to add 0.0.0.0 (or just comment the line out ), save the mongodb.conf file.
In addition mongod is a service on ubuntu so you'll need to run following command in the terminal to restart it to read the new config:
sudo service mongod restart
You can read about sudo here
If you're on windows and are wondering how to edit the config file.
Open the file
Edit the cfg file however you want.
Save as and save it to another folder somewhere else
Copy/cut and past the file back into the bin folder and accept admin permission
Go to windows services and stop->start/restart the MongoDB server service.
Done
trying using your specified mongodb.conf to mongo deamon
use following command to start the mongod daemon
mongod -f <file-locattion>/mongodb.conf
and in your mongodb.conf file add following
bind_ip=<your-pref-ip>
<rest of setting -such as data-folder etc>
using aws ubuntu instance i ssh to my instance using putty navigate to the file directory and
i used the command
sudo pico mongodb.conf
the file opened and i edited my file then saved it
by following onscreen commands

how do I start mongodb via /etc/init.d/mongodb with a config file?

I have a config file for mongo that specifies an alternate port:
deploy#ip-xxx-xxx-22-107 ~/app $ tail /etc/mongodb.conf
port = 27033
Not very complex. I'm trying to use a file based config instead of command line, seems like a better idea. I'm on Ubuntu 11. The docs say:
On some packaged installs of MongoDB (for example Ubuntu & Debian),
the default file can be found in /etc/mongodb.conf, which is
automatically used when starting and stopping MongoDB from the service
I definitely can start mongo with sudo /etc/init.d/mongodb restart but it's starting on the wrong port, 27017:
deploy#ip-xxx-xxx-22-107 ~/app $ sudo lsof -iTCP | grep mongo
mongod 3594 mongodb 5u IPv4 260392 TCP localhost:27017 (LISTEN)
mongod 3594 mongodb 7u IPv4 260395 TCP localhost:28017 (LISTEN)
So there's mongo, but not the right port. Whenever I try passing in a config file to the mongodb command I get an error:
sudo /etc/init.d/mongodb -f /etc/mongodb.conf restart
* ERROR: wrong args ( -f )
I suspect the /etc/init.d/mongodb command isn't passing on my config request when it's starting mongo. But the config file should be read by default according to the docs. Is something wrong with my Ubuntu install (it's on a PaaS host)? Is there no advantage to using /etc/init.d/mongodb so I should just ignore this? I can get it to read the config file via mongod -f /etc/mongodb.conf but my docs say to use /etc/init.d/mongodb.
Where did you install the mongo package from? If you installed from the default repositories, then you may have a very old version - I just tried on 11.04 (don't have 11.10 handy, sorry) and I got 1.6.4 which is very old (current stable release as of writing this is 2.0.2).
You should remove the version you have, and add the one from the 10gen/MongoDB repositories. The instructions for doing so are here:
http://www.mongodb.org/display/DOCS/Ubuntu+and+Debian+packages
That will give you the latest mongod version and likely resolve your issues, because you seem to be doing things correctly.
Once you have the mongod started, then connect to it and try running this:
use admin
db.runCommand({getCmdLineOpts: 1})
That should give you all the passed and parsed options. There is a sample output shown on the Docs page for the command. It should allow you to see where the mongod is pointing for the config file and what is being parsed from it.