Max Krog
Max Krog

Reputation: 181

Cant find /data/db folder (MongoDB)

I'm unable to find my ~/data/db folder that i created for MongoDB.

I created it with "sudo mkdir - p /data/db" in my root folder. I am unsure of what the "sudo" command does as it seems the folder is hidden in some way. If i navigate to the root folder it does not contain a /data/db folder. Altho my MongoDB works and i can save things to the DB.

I've tried "sudo ls" in root with no result.

To get my mongoDB going i have to do: "sudo ./mongod" "sudo ./mongo"

in my mongodb/bin folder.

If i don't type sudo random errors (which i can insert here if needed) appears.

TLDR: Seems like my ~/data/db is under some privacy setting. Cant find it in the finder.

Upvotes: 2

Views: 2774

Answers (1)

Nicolas Rinaudo
Nicolas Rinaudo

Reputation: 6168

sudo means you're creating the folder as the root user, which means that it'll be created with root's default permissions - typically, not enough for other users to work with it.

I'm also confused as to what you're really trying to achieve. Are you trying to create a /data/db folder in your home directory (mkdir -p ~/data/db) or in the root directory (sudo mkdir -p /data/db)? You mention both as if they were equivalent, but they really are not. Assuming your user name is bangalter, the former will be in /home/bangalter/data/db and the later in /data/db. Obviously, if you're sudoing to run mongodb, you're executing it as the root user whose home is neither / nor /home/bangalter, but /home/root.

In short: you're not having issues with mongodb but suffering from a lack of familiarity with unix user management / directory structure. This is easily remedied, however, as there are literally thousands of articles, books and tutorials on those.

Upvotes: 4

Related Questions