question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Getting 500 error due to no mongo connection

See original GitHub issue

When using this plugin for some reason it breaks my database connection. Any ideas why?

{"error":{"name":"MongoError","message":"no connection available"}}

I use the following function to connect to mongo before running my lambda functions.

const mongoose = require('mongoose');

mongoose.Promise = global.Promise;
let cachedDB = null;

module.exports = fn => (...args) => {
  const [, context] = args;

  context.callbackWaitsForEmptyEventLoop = false;

  if (cachedDB && cachedDB.readyState != 0 && cachedDB.readyState != 3) {
    fn(...args);
  } else {
    mongoose.connect(process.env.MONGO_URI);

    mongoose.connection.on('error', err => {
      console.log('Connection Error');
      console.log(err);
    });

    mongoose.connection.once('open', () => {
      cachedDB = mongoose.connection;
      fn(...args);
    });
  }
};

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
pizzarobcommented, Nov 9, 2017

@goncaloneves sorry you took it that way. condescending comments about how I’m doing it wrong don’t warrant a thank you in my book. I won’t be using this plugin.

1reaction
goncalonevescommented, Nov 9, 2017

And another thing, that mustn’t go unmentioned, the next time you open an issue like this one: Say thanks when someone helps you and you expect them to solve your code problem.

Open source tech is about politeness, being thankful and contribute. For all the rest, is a well paid service.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting a 500 internal server error when trying to async open a ...
Now all of a sudden whenever I try and open a realm with my code, I just get a 500 internal server error...
Read more >
500 internal server error while saving data to mongoDB
When i send the data into post request i find the data in the body but in the process of saving this data...
Read more >
Getting "500 Internal Server Error" while posting a request to ...
Coding example for the question Getting "500 Internal Server Error" while posting a request to the MongoDB using Mongoose transaction-mongodb.
Read more >
500 server error on controller | Ubiquiti Community
I'm running 5.2.9 on Ubuntu 14.04.5, and ran some updates yesterday. The controller serves up the website, but I'm getting a 500 Internal...
Read more >
Mongodb 500 Internal error — DataTables forums
I use this php script http://datatables.net/development/server-side/php_mongodb in order to get the rows. On localhost with mongodb on localhost ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found