Getting 500 error due to no mongo connection
See original GitHub issueWhen 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:
- Created 6 years ago
- Comments:8 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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.
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.