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;








0
















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.










share|improve this question















marked as duplicate by Neil Lunn mongodb
Users with the  mongodb badge can single-handedly close mongodb questions as duplicates and reopen them as needed.

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 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


















0
















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.










share|improve this question















marked as duplicate by Neil Lunn mongodb
Users with the  mongodb badge can single-handedly close mongodb questions as duplicates and reopen them as needed.

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 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














0












0








0









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.










share|improve this question

















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 mongodb
Users with the  mongodb badge can single-handedly close mongodb questions as duplicates and reopen them as needed.

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 mongodb
Users with the  mongodb badge can single-handedly close mongodb questions as duplicates and reopen them as needed.

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 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













  • 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








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













0






active

oldest

votes

















0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?