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

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현