How to fix MongoError: server instance pool was destroyed? [duplicate]How do I return the response from an asynchronous call?How to properly reuse connection to Mongodb across NodeJs application and modulesmongoError: Topology was destroyedHow to resolve Mongoose Connect UNKNOWN?How to use Node http request globallyWhy does not sending data io.sockets.emit and socket.broadcast.emitAssertionError: null == MongoError: server instance pool was destroyed“Cannot GET /db/read/getall” accessing node.js express API using reverse proxy nginx on digitalocean dropletmongoose connection error alwaysMongoError “server instance pool was destroyed”MongoError: server instance pool was destroyedMongoClient throw MongoError: server instance pool was destroyed
The selling of the sheep
Gerrymandering Puzzle - Rig the Election
Antivirus for Ubuntu 18.04
Huffman Code in C++
What's the 2-minute timer on mobile Deutsche Bahn tickets?
Collision domain question
How can I finally understand the confusing modal verb "мочь"?
What does the coin flipping before dying mean?
TIP120 Transistor + Solenoid Failing Randomly
How did the Apollo guidance computer handle parity bit errors?
Reverse ColorFunction or ColorData
Which "exotic salt" can lower water's freezing point by –70 °C?
Problem with estimating a sequence with intuition
Changing stroke width vertically but not horizontally in Inkscape
Game artist computer workstation set-up – is this overkill?
Was there a dinosaur-counter in the original Jurassic Park movie?
How to use awk to extract data from a file based on the content of another file?
Is it normal for gliders not to have attitude indicators?
GitLab account hacked and repo wiped
Where did Lovecraft write about Carcosa?
Does Thanos's ship land in the middle of the battlefield in "Avengers: Endgame"?
Ab major 9th chord in Bach
Efficient deletion of specific list entries
All of my Firefox add-ons been disabled suddenly, how can I re-enable them?
How to fix MongoError: server instance pool was destroyed? [duplicate]
How do I return the response from an asynchronous call?How to properly reuse connection to Mongodb across NodeJs application and modulesmongoError: Topology was destroyedHow to resolve Mongoose Connect UNKNOWN?How to use Node http request globallyWhy does not sending data io.sockets.emit and socket.broadcast.emitAssertionError: null == MongoError: server instance pool was destroyed“Cannot GET /db/read/getall” accessing node.js express API using reverse proxy nginx on digitalocean dropletmongoose connection error alwaysMongoError “server instance pool was destroyed”MongoError: server instance pool was destroyedMongoClient throw MongoError: server instance pool was destroyed
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
This question already has an answer here:
How do I return the response from an asynchronous call?
34 answers
How to properly reuse connection to Mongodb across NodeJs application and modules
11 answers
My objective is to simply insert a message into database from a form post.
I have tried the following code without using any framework.
const http = require('http');
const MongoClient = require('mongodb').MongoClient;
var qs = require('querystring');
var url = require('url');
const hostname = '127.0.0.1';
const port = 3000;
const uri = 'mongodb://localhost:27017';
const client = new MongoClient(uri, useNewUrlParser: true );
var messages = "";
const server = http.createServer((req,res) =>
res.statusCode = 200;
res.setHeader('Content-Type', 'text/html');
res.write(`
<!doctype html>
<html>
<body>
<form action="/" method="post">
<input type="text" name="message" />
<button>Insert</button>
</form>
</body>
</html>);
if (req.method === 'POST')
var body = '';
req.on('data', function (data)
body += data;
);
req.on('end', function ()
var post = qs.parse(body);
client.connect(err =>
const collection = client.db("mydb").collection("messages");
collection.insertOne(post, function(err, res)
if(err) throw err;
console.log("1 document inserted");
client.close(); // Either I place it here or don't close the connection at all still showing error
)
);
);
);
server.listen(port, hostname, () =>
console.log(`Server running at http://$hostname:$port/`);
);
Now when I run the app it constantly loading/requesting and after submitting a message its throwing error "MongoError: server instance pool was destroyed". Please assist me what is the proper way to achieve the goal or any workaround. Thanks.
node.js mongodb
marked as duplicate by Neil Lunn
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Mar 23 at 4:55
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
How do I return the response from an asynchronous call?
34 answers
How to properly reuse connection to Mongodb across NodeJs application and modules
11 answers
My objective is to simply insert a message into database from a form post.
I have tried the following code without using any framework.
const http = require('http');
const MongoClient = require('mongodb').MongoClient;
var qs = require('querystring');
var url = require('url');
const hostname = '127.0.0.1';
const port = 3000;
const uri = 'mongodb://localhost:27017';
const client = new MongoClient(uri, useNewUrlParser: true );
var messages = "";
const server = http.createServer((req,res) =>
res.statusCode = 200;
res.setHeader('Content-Type', 'text/html');
res.write(`
<!doctype html>
<html>
<body>
<form action="/" method="post">
<input type="text" name="message" />
<button>Insert</button>
</form>
</body>
</html>);
if (req.method === 'POST')
var body = '';
req.on('data', function (data)
body += data;
);
req.on('end', function ()
var post = qs.parse(body);
client.connect(err =>
const collection = client.db("mydb").collection("messages");
collection.insertOne(post, function(err, res)
if(err) throw err;
console.log("1 document inserted");
client.close(); // Either I place it here or don't close the connection at all still showing error
)
);
);
);
server.listen(port, hostname, () =>
console.log(`Server running at http://$hostname:$port/`);
);
Now when I run the app it constantly loading/requesting and after submitting a message its throwing error "MongoError: server instance pool was destroyed". Please assist me what is the proper way to achieve the goal or any workaround. Thanks.
node.js mongodb
marked as duplicate by Neil Lunn
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Mar 23 at 4:55
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
2
client.close()
is being invoked "outside" of a callback when it needs to be "inside". In fact your code for a http server really should never callclient.close()
at all. Please look at the "first" linked duplicate for reference on callbacks and their relation to flow control in your application. Please also see the second linked duplicate for reference on how to handle connections properly within your application.
– Neil Lunn
Mar 23 at 4:56
add a comment |
This question already has an answer here:
How do I return the response from an asynchronous call?
34 answers
How to properly reuse connection to Mongodb across NodeJs application and modules
11 answers
My objective is to simply insert a message into database from a form post.
I have tried the following code without using any framework.
const http = require('http');
const MongoClient = require('mongodb').MongoClient;
var qs = require('querystring');
var url = require('url');
const hostname = '127.0.0.1';
const port = 3000;
const uri = 'mongodb://localhost:27017';
const client = new MongoClient(uri, useNewUrlParser: true );
var messages = "";
const server = http.createServer((req,res) =>
res.statusCode = 200;
res.setHeader('Content-Type', 'text/html');
res.write(`
<!doctype html>
<html>
<body>
<form action="/" method="post">
<input type="text" name="message" />
<button>Insert</button>
</form>
</body>
</html>);
if (req.method === 'POST')
var body = '';
req.on('data', function (data)
body += data;
);
req.on('end', function ()
var post = qs.parse(body);
client.connect(err =>
const collection = client.db("mydb").collection("messages");
collection.insertOne(post, function(err, res)
if(err) throw err;
console.log("1 document inserted");
client.close(); // Either I place it here or don't close the connection at all still showing error
)
);
);
);
server.listen(port, hostname, () =>
console.log(`Server running at http://$hostname:$port/`);
);
Now when I run the app it constantly loading/requesting and after submitting a message its throwing error "MongoError: server instance pool was destroyed". Please assist me what is the proper way to achieve the goal or any workaround. Thanks.
node.js mongodb
This question already has an answer here:
How do I return the response from an asynchronous call?
34 answers
How to properly reuse connection to Mongodb across NodeJs application and modules
11 answers
My objective is to simply insert a message into database from a form post.
I have tried the following code without using any framework.
const http = require('http');
const MongoClient = require('mongodb').MongoClient;
var qs = require('querystring');
var url = require('url');
const hostname = '127.0.0.1';
const port = 3000;
const uri = 'mongodb://localhost:27017';
const client = new MongoClient(uri, useNewUrlParser: true );
var messages = "";
const server = http.createServer((req,res) =>
res.statusCode = 200;
res.setHeader('Content-Type', 'text/html');
res.write(`
<!doctype html>
<html>
<body>
<form action="/" method="post">
<input type="text" name="message" />
<button>Insert</button>
</form>
</body>
</html>);
if (req.method === 'POST')
var body = '';
req.on('data', function (data)
body += data;
);
req.on('end', function ()
var post = qs.parse(body);
client.connect(err =>
const collection = client.db("mydb").collection("messages");
collection.insertOne(post, function(err, res)
if(err) throw err;
console.log("1 document inserted");
client.close(); // Either I place it here or don't close the connection at all still showing error
)
);
);
);
server.listen(port, hostname, () =>
console.log(`Server running at http://$hostname:$port/`);
);
Now when I run the app it constantly loading/requesting and after submitting a message its throwing error "MongoError: server instance pool was destroyed". Please assist me what is the proper way to achieve the goal or any workaround. Thanks.
This question already has an answer here:
How do I return the response from an asynchronous call?
34 answers
How to properly reuse connection to Mongodb across NodeJs application and modules
11 answers
node.js mongodb
node.js mongodb
edited Mar 23 at 5:18
Hasan Al Khaled
asked Mar 23 at 4:50
Hasan Al KhaledHasan Al Khaled
65
65
marked as duplicate by Neil Lunn
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Mar 23 at 4:55
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Neil Lunn
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Mar 23 at 4:55
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
2
client.close()
is being invoked "outside" of a callback when it needs to be "inside". In fact your code for a http server really should never callclient.close()
at all. Please look at the "first" linked duplicate for reference on callbacks and their relation to flow control in your application. Please also see the second linked duplicate for reference on how to handle connections properly within your application.
– Neil Lunn
Mar 23 at 4:56
add a comment |
2
client.close()
is being invoked "outside" of a callback when it needs to be "inside". In fact your code for a http server really should never callclient.close()
at all. Please look at the "first" linked duplicate for reference on callbacks and their relation to flow control in your application. Please also see the second linked duplicate for reference on how to handle connections properly within your application.
– Neil Lunn
Mar 23 at 4:56
2
2
client.close()
is being invoked "outside" of a callback when it needs to be "inside". In fact your code for a http server really should never call client.close()
at all. Please look at the "first" linked duplicate for reference on callbacks and their relation to flow control in your application. Please also see the second linked duplicate for reference on how to handle connections properly within your application.– Neil Lunn
Mar 23 at 4:56
client.close()
is being invoked "outside" of a callback when it needs to be "inside". In fact your code for a http server really should never call client.close()
at all. Please look at the "first" linked duplicate for reference on callbacks and their relation to flow control in your application. Please also see the second linked duplicate for reference on how to handle connections properly within your application.– Neil Lunn
Mar 23 at 4:56
add a comment |
0
active
oldest
votes
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
2
client.close()
is being invoked "outside" of a callback when it needs to be "inside". In fact your code for a http server really should never callclient.close()
at all. Please look at the "first" linked duplicate for reference on callbacks and their relation to flow control in your application. Please also see the second linked duplicate for reference on how to handle connections properly within your application.– Neil Lunn
Mar 23 at 4:56