0

I'm trying to build a simple CRUD app with a MEAN stack, here's my file tree so far:

-app
-node_modules
-server
  -config
     -db.js
  -controllers
     -user.api.js
  -models
     -user.js
  -routes
     -api.js
     -web.js 
-package.json
-server.js

When running mongod I got the following error:

2017-12-03T15:25:53.243-0500 I CONTROL  [initandlisten] MongoDB starting : pid=57220 port=27017 dbpath=/data/db 64-bit host=Carloss-MacBook-Pro.local
2017-12-03T15:25:53.244-0500 I CONTROL  [initandlisten] db version v3.4.10
2017-12-03T15:25:53.244-0500 I CONTROL  [initandlisten] git version: 078f28920cb24de0dd479b5ea6c66c644f6326e9
2017-12-03T15:25:53.244-0500 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2m  2 Nov 2017
2017-12-03T15:25:53.244-0500 I CONTROL  [initandlisten] allocator: system
2017-12-03T15:25:53.244-0500 I CONTROL  [initandlisten] modules: none
2017-12-03T15:25:53.244-0500 I CONTROL  [initandlisten] build environment:
2017-12-03T15:25:53.244-0500 I CONTROL  [initandlisten]     distarch: x86_64
2017-12-03T15:25:53.244-0500 I CONTROL  [initandlisten]     target_arch: x86_64
2017-12-03T15:25:53.244-0500 I CONTROL  [initandlisten] options: {}
2017-12-03T15:25:53.247-0500 I STORAGE  [initandlisten] exception in initAndListen: 29 Data directory /data/db not found., terminating
2017-12-03T15:25:53.247-0500 I NETWORK  [initandlisten] shutdown: going to close listening sockets...
2017-12-03T15:25:53.247-0500 I NETWORK  [initandlisten] shutdown: going to flush diaglog...
2017-12-03T15:25:53.247-0500 I CONTROL  [initandlisten] now exiting
2017-12-03T15:25:53.247-0500 I CONTROL  [initandlisten] shutting down with code:100

So I tried to specify the path of my folder to /server/config/db but that still didn't work. Am I writing the path incorrectly?

This is what I have in my db file:

var mongoose = require('mongoose');
var connection = mongoose.connect('mongodb://localhost/mean_db');

module.exports = connection;
  • 1
    Have you tried starting mongod pointing to your custom data directory i.e `mongod --dbpath=\server\config\db` – Cyclonecode Dec 03 '17 at 20:46
  • 1
    The issue is that the db path (where mongo saves the dbs) doesn't exist or have wrong permissions. check if /data/db exist, and if it doesn't then create it and set the user and group as mongo (or mongodb, it differs) – Diego Velez Dec 03 '17 at 20:46
  • 1
    This link might be helpful: https://stackoverflow.com/questions/5961145/changing-mongodb-data-store-directory – Cyclonecode Dec 03 '17 at 20:47
  • 1
    @Cyclonecode that worked, thanks. –  Dec 03 '17 at 20:58

0 Answers0