Pretext: this has been asked before and i've tried implementing several solutions from previous posters. The only thing i can seem to get working is running mongo as sudo.
I'm not exactly sure what i'm doing wrong. I'm trying to do a tutorial using mongodb and every time i try to run the software i get back an error that its in a read-only directory. I'm on a mac running OS Sierra, i can force run it with sudo but i know thats wrong. I've been searching for an answer for awhile and i have already adjusted the folder permissions to 775 and nothing, then 777, still nothing.
Any help pointing me in the right direction would be greatly appreciated!
to resolve the "warning soft rlimits to low" check out this link - https://gist.github.com/tamitutor/6a1e41eec0ce021a9718
Lets start over as you are bouncing around on what you are trying.
Open activity monitor and kill any mongod process.
Go to your terminal and type which mongo - lets say it shows you download directory
cd to that directory and you should be in the bin directory
cd /mongo download directory/bin
sudo bash
mkdir -p /data/db
chmod 777 /data
chmod 777 /data/db
ls -ld /data/db this will validate you see the data/db directory as 777
exit
You're back in your mongo bin directory - if you are in /usr/local/bin skip this part.
If you are not in /usr/local/bin you will need to copy the mongo files to /usr/local/bin
sudo bash
ls - make sure you are in the correct directory
cp * /usr/local/bin
exit
which mongo should now show /usr/local/bin
type mongod to start it
open a new terminal and type mongo to connect to the instance
I recommend downloading Robo 3T (formally RoboMongo) to quickly check that you can connect.
If you do those steps, you should have no issues connecting to your local Mongo instance.
Your mongod.conf files should be in /usr/local/etc - check there to confirm you have your local host set.
Should be like net:
bindIp:127.0.0.1
I have a file named db.sh in bin folder and when I try to execute this command $ sh bin/db.sh I receive bin/db.sh: line 2: mongod: command not found in console what is wrong there?
#!/bin/sh
mongod --dbpath db --rest --jsonp;
Here is the situation:
which mongod would give you the path to the mongod binary. If there is no output from which, there which could not find mongod. This may be the case that there is not path in the $PATH variable, that contains the mongod binary. You can make sure by executing echo $PATH.
If you have your MongoDB installed manually, in some directory, then you will need to add /path/to/your/mongodb/bin to the $PATH variable in your .bashrc, like this:
PATH=/path/to/your/mongodb/bin:$PATH
But anyway :) seems like you do not have MongoDB installed on your machine. Follow this article to install it.
I am trying to do a mongorestore command and I am not sure how to find the directory of where the data is.
The command is something like this:
mongorestore -v --db new_db_dump [path to the dump directory]
and I am not sure how to find where on my local computer the current dump is so I don't know what the [path to the dump directory] is supposed to be.
Any ideas for how to find it? I am on a mac.
Thanks!
By default, mongodump places its output in a sub-directory named "dump" in the current working directory. If you forgot where you were when you executed mongodump, try searching for "dump" in the finder, look at the resulting folders named "dump", and examine the contents. There will be a sub-directory inside "dump" for each of your databases.
I was following this quickstart guide, http://www.mongodb.org/display/DOCS/Quickstart+OS+X, but I got lost when they told me to to execute ./mongodb-xxxxxxx/bin/mongod, in which directory do I execute this command? I tried to find / -name mongodb results matched that directory format.
To start Mongo, run that command in the root installation directory of mongo, so, assuming you installed mongo in /opt/mongo/mongodb-linux-x86_64-2.0.2, just run in that folder like this...
/opt/mongo/mongodb-linux-x86_64-2.0.2$ ./bin/mongod
Add any additional parameters you need to start the instance, this is how I run my instance....
./bin/mongod --fork --dbpath /opt/mongo/data/db1/dbs --port 33479 --logpath /opt/mongo/data/db1/log/db1.log -logappend
My personal favorite way to install just about anything, including MongoDB, on Mac OS X:
/usr/bin/ruby -e "$(curl -fsSL https://raw.github.com/gist/323731)"
brew install mongodb
My host came with a mongodb instance and there is no /db directory so now I am wondering what I can do to find out where the data is actually being stored.
mongod defaults the database location to /data/db/.
If you run ps -xa | grep mongod and you don't see a --dbpath which explicitly tells mongod to look at that parameter for the db location and you don't have a dbpath in your mongodb.conf, then the default location will be: /data/db/ and you should look there.
What does your configuration file say?
$ grep dbpath /etc/mongodb.conf
If it is not correct, try this, your database files will be present on the list:
$ sudo lsof -p `ps aux | grep mongodb | head -n1 | tr -s ' ' | cut -d' ' -f 2` | grep REG
It's /var/lib/mongodb/* on my default installation (Ubuntu 11.04).
Note that there is also a /var/lib/mongodb/mongod.lock file holding mongod PID for convenience, however it is located in the data directory - which we are looking for...
I find db.serverCmdLineOpts() the most robust way to find actual path if you can connect to the server. The "parsed.storage.dbPath" contains the path your server is currently using and is available both when it's taken from the config or from the command line arguments.
Also in my case it was important to make sure that the config value reflects the actual value (i.e. config didn't change after the last restart), which isn't guaranteed by the solutions offered here.
db.serverCmdLineOpts()
Example output:
{
"argv" : [
// --
],
"parsed" : {
"config" : "/your-config",
"storage" : {
"dbPath" : "/your/actual/db/path",
// --
}
},
"ok" : 1.0
}
In the newer version of mongodb v2.6.4 try:
grep dbpath /etc/mongod.conf
It will give you something like this:
dbpath=/var/lib/mongodb
And that is where it stores the data.
While this question asks about Linux/Unix instances of Mongo, it's one of the first search results regardless of the operating system used, so for future Windows users that find this:
If MongoDB is set up as a Windows Service in the default manner, you can usually find it by looking at the 'Path to executable' entry in the MongoDB Service's Properties:
From my experience the default location is /var/lib/mongodb after I do
sudo apt-get install -y mongodb-org
Actually, the default directory where the mongod instance stores its data is
/data/db on Linux and OS X,
\data\db on Windows
To check the same, you can look for dbPath settings in mongodb configuration file.
On Linux, the location is /etc/mongod.conf, if you have used package manager to install MongoDB.
Run the following command to check the specified directory:
grep dbpath /etc/mongodb.conf
On Windows, the location is <install directory>/bin/mongod.cfg. Open mongod.cfg file and check for dbPath option.
On macOS, the location is /usr/local/etc/mongod.conf when installing from MongoDB’s official Homebrew tap.
The default mongod.conf configuration file included with package manager installations uses the following platform-specific default values for storage.dbPath:
+--------------------------+-----------------+------------------------+
| Platform | Package Manager | Default storage.dbPath |
+--------------------------+-----------------+------------------------+
| RHEL / CentOS and Amazon | yum | /var/lib/mongo |
| SUSE | zypper | /var/lib/mongo |
| Ubuntu and Debian | apt | /var/lib/mongodb |
| macOS | brew | /usr/local/var/mongodb |
+--------------------------+-----------------+------------------------+
The storage.dbPath setting in the configuration file is available only for mongod.
The Linux package init scripts do not expect storage.dbPath to change from the defaults. If you use the Linux packages and change storage.dbPath, you will have to use your own init scripts and disable the built-in scripts.
Source
I found mine here on a OSX system
/usr/local/var/mongodb
For windows Go inside MongoDB\Server\4.0\bin folder and open mongod.cfg file in any text editor. Then locate the line that specifies the dbPath param. The line looks something similar
dbPath: D:\Program Files\MongoDB\Server\4.0\data
On MongoDB 4.4+ and on CentOS 8, I found the path by running:
grep dbPath /etc/mongod.conf
Found it just by poking around in /var/db. Thanks for the help though--I am sure these answers apply to other systems (e.g. Ubuntu) and will help others!
If you could somehow locate mongod.log and the do a grep over it
grep dbpath mongod.log
The value for dbpath is the data location for mongodb!!
All the best :)
When you start it up it shows you. But I don't know if it is something you can do or not on your host. If you have access to the command line and can restart the service, you will get something like:
2016-11-15T12:57:09.182-0500 I CONTROL [initandlisten]
MongoDB starting : pid=16448 port=27017 dbpath=C:\data\db\