scottwrobinson / camo

A class-based ES6 ODM for Mongo-like databases.
556 stars 80 forks source link

How do you properly close a connection? How do you handle connection/socket errors? #33

Closed niftylettuce closed 8 years ago

niftylettuce commented 8 years ago

How are these errors handled? I'm coming from Mongoose

michaeljota commented 8 years ago

You can search in closed issues. He make this with Promises. Short answer: Just catch the error, like a Promise. (.then().catch();)

niftylettuce commented 8 years ago

@michaeljota how can we await a db connection before starting our app?

niftylettuce commented 8 years ago

https://github.com/scottwrobinson/camo/issues/17#issue-120250106

michaeljota commented 8 years ago

IDK. But, I see something like like that as a title of some close issue.

ref #30

niftylettuce commented 8 years ago

Here's how I did it (I'm using Koa):

 // connect to the db
connect(config.db).then(db => {
  console.log(`MongoDB connected to ${config.db}`);
}).catch(err => {
  console.error(err);
  process.exit(1);
});

// initialize the app
const app = new Koa();