Unable to create a database

175 views
Skip to first unread message

bertie tozer

unread,
Jan 20, 2019, 5:54:30 PM1/20/19
to mongodb-user
Hello 

I really need some help please, I have installed Homebrew and installed mogodb with homebrew but I have been unable to create a database at all.

🍺  /usr/local/Cellar/mongodb/4.0.3_1: 18 files, 258.1MB

Cecils-MacBook-Pro:~ negro75$ mkdir -p /data/db

mkdir: /data/db: Permission denied

Cecils-MacBook-Pro:~ negro75$ > sudo chown -r 'id -un' /data/db

chown: illegal option -- r

usage: chown [-fhv] [-R [-H | -L | -P]] owner[:group] file ...

       chown [-fhv] [-R [-H | -L | -P]] :group file ...

Cecils-MacBook-Pro:~ negro75$ >> sudo chown -R $USER /data/db

chown: /data/db: No such file or directory



Cecils-MacBook-Pro:~ negro75$ mongo

MongoDB shell version v4.0.3

connecting to: mongodb://127.0.0.1:27017

2019-01-20T14:23:55.495+0100 E QUERY    [js] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :

connect@src/mongo/shell/mongo.js:257:13

@(connect):1:6

exception: connect failed

Cecils-MacBook-Pro:~ negro75$ 


This is what I tried last, as you can see it is not working.

Please can someone help me as I really need this working, I have a massive amount of work to do and I am held back by the fact I cannot create a database for mongodb.

Any help with this would be amazing as I have not been able to fix this problem.

Thank you 

Oleg Toropov

unread,
Jan 20, 2019, 7:09:28 PM1/20/19
to mongod...@googlegroups.com
mkdir: /data/db: Permission denied

This is your problem. you (your user) do not have permission to create directory.


--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/9616f501-934e-4f5a-86f1-2941fe60a288%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
//
// Oleg V.Toropov, MCP | oleg.t...@gmail.com
// -----------------------------------------------------------------
// I have discovered that if I read enough stuff that's over my head,
// I actually begin to understand some of it.
//

Robert Cochran

unread,
Jan 20, 2019, 8:09:20 PM1/20/19
to mongodb-user
Hi!

This link gives you the  official directions for installing MongoDB on MacOS. As Oleg mentions, you need to give the user named 'mongodb' read-write-list (rwx) permissions on the entire /data/db directory and also the /var/log/mongodb.

A long time ago, I installed MongoDB on MacOS by creating a login account named mongodb. Then I created /data/db and the necessary logging directories, and that worked fine.

If you are in a MongoDB University class like M001, the course very likely has videos that will show you step by step how to do a MacOS installation. From what I have seen over the years, I get the impression that lots of the MongoDB employees themselves use MacOS.

Be aware that MacOS Sierra, High Sierra, and Mojave -- those releases -- have increasingly stricter security requirements, and you might have to relax the security restrictions if Apple has not approved the MongoDB installer. I'm not sure what the specific security issues are nowadays. I am only saying there might be further security issues, not that there are. 

I myself no longer use MacOS-based MongoDB installations. Instead, I install MongoDB on a Linux server and do all my MongoDB work on that server. It makes more sense for me to install MongoDB on bunches of virtual machines, too. 

Thanks so much

Bob

bertie tozer

unread,
Jan 21, 2019, 2:47:47 AM1/21/19
to mongod...@googlegroups.com
Thak you all but I have given up, it has proved impossible to install via Homebrew or any other way I have tried on both of my MacBook Pro, I will just have to find another way of building my API, I have read the documentation many times, it has not helped, I have watched every video I can find on YouTube, and I have been using computers since 1999 so I have a clue about what I am doing, but it has proved impossible for me to setup mongodb on any of my MacBook Pro, I do not have the time to keep trying to get this to work so I have little choce but to find an alternative.

thank you very much for your help.

--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: https://docs.mongodb.com/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.

Tim Hawkins

unread,
Jan 21, 2019, 3:10:14 AM1/21/19
to mongodb-user
Mongodb is trivialy easy to install, on almost every platform i have every used.  The instructions in the document provided are very clear. I cant help thinking you have not followed them accuratly or have skipped steps. 

The only item i could see that may have caused you issue was the lake of the use of sudo when creating the data directory. 

Ie use

"sudo mkdir -p /data/db"

Otherwise you dont have tbe right permissions to create the data diredtory, which was what you where seeing in the response you posted,  did you not check that the data directory actualy existed?



Robert Cochran

unread,
Jan 21, 2019, 8:06:18 AM1/21/19
to mongodb-user
This is closer to what Bertie needs but is not complete. I should have stated this in my reply above. 

In modern (current) OS X systems, the first user on the system has some but not all administrative privileges. 

There should be a 'mongodb' user on the system and this user should be a standard user, not an administrative user.

To make a directory under / (root), you need administrative privileges. `mkdir' creates a directory but does not set ownership or permissions on the directory. To set ownership, you need `'chown'. To set permissions, you need 'chmod'. 

sudo mkdir -p /data/db
sudo chown
-R mongodb:mongodb /data/db
sudo chmod
-R ugo+rwx /data/db



I don't really think installing under Homebrew is necessary; indeed Homebrew can add more complexity because it also wants to build and launch its own binaries and it might also use binaries which are simply outdated for a system. It is better to directly install on a fully updated MacOS system.

One last thing: the MacOS system should have Xcode installed on it plus the "Command Line Tools". These are separate installable packages from Apple and you must have them installed. 

Thanks

Bob

Robert Cochran

unread,
Jan 21, 2019, 8:22:21 PM1/21/19
to mongodb-user
Hi,

To help you a little bit more, I want to show my own corresponding data and log directories for MongoDB and the permissions on those directories. This instance is not on MacOS. Rather, it is running under Ubuntu 18.04.1 LTS. However since MacOS is very Unix-like under the hood, it uses a similar directory and system of file permissions. So the concept transfers well to Mac OS.

In your /etc/mongod.conf file, you can specify to the database server the path for the data and log directories. Here is my own path as coded into my mongod.conf:

storage:

  dbPath: /media/mongo/data


 This is the /media/mongo directory:

drwxr-xr-x  4 mongodb mongodb   34 May  9  2018 mongo


That directory has 755 permissions on it I believe -- so you don't need rwx (read-write-list) permissions on the group and other bits. You really do not want your database directories world writable. I should not have suggested rwx permissions on the world bits earlier. r-x permissions for the world are sufficient. (If you don't understand how permissions on Unix filesystems work, you should Google and read about them. It only takes about 10 minutes of reading.)

So this is my data directory under /media/mongo:

drwxr-xr-x 4 mongodb mongodb 16384 Jan 17 21:41 data


As you can see the same 755 permissions are there and they are sufficient for the server's needs.

Where did that 'mongodb' come from? Well I have a user named mongodb. Your system needs to have one too. Here is what mongodb looks like when I check /etc/passwd:

mongodb:x:111:65534::/home/mongodb:/usr/sbin/nologin


In my case, the mongodb user doesn't need a login shell, so I set it up so there is no login for this guy. 

The same concepts apply to the logging directory. Look in your /etc/mongod.conf file to discover the path to the logging directory and make sure it has rwx permissions for the 'mongodb' user.

How come I didn't use the default /data/db directory names? Well I wanted to write to an xfs-formatted filesystem, and I created one under /media for that purpose. You don't need to do this, at least not for purposes of a successful install on the Mac.

I hope this helps you out.

Bob
Reply all
Reply to author
Forward
0 new messages