how do I edit the Mondodb.conf file - mongodb

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

Related

Change default MongoDB port on Ubuntu Snap installation

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)

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.

Fix mongod install via command line

After installing mongodb on windows, I set up the necessary folders but made a typing mistake when doing the following command:
mongod --directoryperdb --dbpath C:\mondodb\data\db --logpath C:\mongodb\log\mongo.log --logappend --rest --install
the folder is named mongodb but i named it mondodb by accident and can't seem to overwrite that, so when I start mongodb by doing net start mongodb I get an error in my log saying C:\mondodb\data\db not found
I tried redoing it like so mongod --directoryperdb --dbpath C:\mongodb\data\db --logpath C:\mongodb\log\mongo.log --logappend --rest --install but it's not working.
how can I redo the mongod thingy?
There are a few different things you could try:
Go into the registry and change the service path: Modifying the "Path to executable" of a windows service. After you modify it, you can go into Services.msc, right-click on the service, go to Properties, then Look at the Path to executable: and make sure that it points to mongodb rather than mondodb.
It involves editing the registry, but service information can be found in HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services. Find the service you want to redirect, locate the ImagePath subkey and change that value.
Go into a command prompt (may need to Run as Administrator) and do sc delete mongod <or whatever the service is named> -- can check services.msc for that). Then re-run your command with the correct path.
Alternately, you might try to set it up by taking a config file so that you can just change those options via config file rather than having to modify the service or delete/reinstall the service when you want to change options. I believe the command there is C:\<mongopath>\mongod.exe -f <config file name> --install.

Unable to start mongodb

I'm trying to install mongodb on my window 7 machine. When trying to start it by using the mongod command I get this error. dbpath (\data\db) does not exist. I followed the steps ath the tutorial. All the folders exist C:\mongodb\log, C:\mongodb\data and C:\mongodb\data\db .
The default path is c:\data\db. You are trying to use c:\mongodb\data\db.
This means you have to use the option --dbpath c:\mongodb\data\db for mongod command.
By default, when we start the mongodb, it looks for the folder /data/db (on Mac/Linux) or C:\data\db (on windows)...however, during the installation it doesn't create this folder, so when when we run mongodb for the first time, it fails with the error that it can't find C:\data\db folder. The solution is to manually create C:\data\db folder and then start mongodb. This error can be totally avoided if the mongodb installer can just give an option to choose this folder path and then create it as part of mongodb installation itself.
In windows you might not have permission for your user. And mongo installer could not create it because of lack of Administrative permission for your user.
So in C:\Program Files\MongoDB:
Create a folder named data
Create a folder named db inside the folder data
Now right click on the data folder and choose properties
Click security tab and select your user there
Click the Full control select box
Click ok, ok, ok ...
important! if you don't have the path "C:\Program Files\MongoDB\Server\3.4\bin" set in environment variable, please set it.
Now go to shell and type : mongod --dbpath "C:\Program Files\MongoDB\data\db"
That's it :)
Try to use 2 command Prompts (CMD) at the same time.
First CMD, use the command:
mongod (or mongod --dbpath C:\mongodb\data)
Second CMD, use the command:
mongo
The second will connect in the database. Do not close the first.

How do I force save the dbpath parameter?

I'm just starting out with developing with Mongodb locally and following the tutorials.
I want to use 1 path for all my development.
In the Mongodb documentation it says:
Create a data directory
By default MongoDB will store data in
/data/db, but it won't automatically
create that directory. To create it,
do:
$ mkdir -p /data/db
You can also tell
MongoDB to use a different data
directory, with the --dbpath option.
I want to use one path for all my dbpaths so that I know where they all are and not get confused.
The path I want to use is:
sudo mongod --config=/Applications/XAMPP/xamppfiles/var/mongodb/mongodb.conf
The mongodb.conf file I have is set up as thus:
# Store data alongside MongoDB instead of the default, /data/db/
dbpath = /Applications/XAMPP/xamppfiles/var/mongodb
# Only accept local connections
bind_ip = 127.0.0.1
However, I have noticed that I have to keep typing this config path in every time I want to run Mongo.
How do I make it so that Mongodb save the dbpath, or the path to the config without me having to type it out every time?
Thanks.
You can create a startup script, like a bash/cshc script. You must specify those options when starting up.
Make a bash script that runs the commands you want.
Make a file called startMongo.sh
#! /bin/bash
mongod --config=/Applications/XAMPP/xamppfiles/var/mongodb/mongodb.conf
Run command
sudo startMongo.sh