Skip to content
This repository has been archived by the owner on Mar 8, 2021. It is now read-only.

Mongodb connection #60

Open
madmansn0w opened this issue Oct 18, 2020 · 0 comments
Open

Mongodb connection #60

madmansn0w opened this issue Oct 18, 2020 · 0 comments

Comments

@madmansn0w
Copy link

madmansn0w commented Oct 18, 2020

In config/index.js

 database: {
    mongoURL: 'mongodb://localhost:27017/example',
  },

needs to be changed to:

 database: {
    mongoURL: 'mongodb://localhost:27017/',
    name: 'databaseName',
  },

And subsequently, build/dev-server.js needs the following change:

// Create a MonboDB connection pool and start the Node.js app
MongoClient.connect(config.database.mongoURL, { promiseLibrary: Promise })
  .catch(err => console.error(err.stack))
  .then((db) => {
    app.locals.db = db; // See http://expressjs.com/en/4x/api.html#app.locals
    app.listen(port);
     
     ...

  });

to:

MongoClient.connect(config.database.mongoURL, { promiseLibrary: Promise })
  .catch(err => console.error(err.stack))
  .then((client) => {
    app.locals.db = client.db(config.database.name);
    app.listen(port);

    ...

  });

To reflect the changes made to in Mongodb v3+
Specifically:
version 3+ has connectCallback(error, client)
version 2 has connectCallback(error, db)

so there's an extra step in getting the collections.

I'd make a pull request, but I actually do not know how to do this yet.

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

No branches or pull requests

1 participant