Skip to content

Setting Up mongo #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Aeal opened this issue Jan 18, 2014 · 3 comments
Closed

Setting Up mongo #60

Aeal opened this issue Jan 18, 2014 · 3 comments

Comments

@Aeal
Copy link

Aeal commented Jan 18, 2014

Im pretty sure this is a user error. I am trying to connect to a local database and I change the development url in the congfiguration to point to my local instance, but when I run grunt serve I get an error saying required MongoStore option db missing. This looks like an awesome package and thank you for putting it together I just need some help getting started!

@DaftMonk
Copy link
Member

Could you post your configuration and the error? Also, does it run with the default configuration?

@Mikevin
Copy link

Mikevin commented Jan 21, 2014

The problem is in this snippet generated by default config:

    app.use(express.session({
      secret: 'angular-fullstack secret',
      store: new mongoStore({
        url: config.mongo.uri,
        collection: 'sessions'
      })
    }));

Which are lines 46-52 from express.js.
They should probably be:

    app.use(express.session({
      secret: 'angular-fullstack secret',
      store: new mongoStore({
        url: config.mongo.url + '/sessions'
      })
    }));

There is also a 'mongoose_connection' option in mongoStore, which could be used also.

@joshperry
Copy link

I think the problem here is in the configuration.

In config.js lodash.extend() is used to combine the global config values with the environment specific config values.

In all.js

module.exports = {
  root: rootPath,
  port: process.env.PORT || 3000,
  mongo: {
    options: {
      db: {
        safe: true
      }
    }
  }
};

In development.js

module.exports = {
  env: 'development',
  mongo: {
    uri: 'mongodb://localhost/fullstack-dev'
  }
};

In config.js

module.exports = _.extend(
    require('./env/all.js'),
    require('./env/' + process.env.NODE_ENV + '.js') || {});

extend() is not recursive and will not merge the mongo object in these config hashes so the environment specific mongo overwrites the one in all.js. You end up with a mongo object that has just the uri property and no options property.

There are two ways to fix this, the easiest is to replace _.extend(...) in config.js with _.merge(...), this will do a "deep extend" and merge the full object trees. The other is to flatten the config hierarchy and have something like mongoUri and mongoConfig, but then you have to update any references to the mongo config value in the rest of the codebase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants