EADDRINUSE Node.js MongoDB Callbacks issue -


the problem: (node.js application + mongodb native driver) have json file more 60000 json documents.the documents creation date , unique id called vid. , need insert in mongodb collection. need insert new vid or update ones existing document more recent.

what did: https://github.com/telmoivo/pfc/blob/master/cfginit.js

what happening: after inserting/updating 500 times , getting 287 documents in collection error: assertionerror: null == { [mongoerror: connect eaddrinuse] name : 'mongoerror', message: 'connect eaddrinuse' } @ line assert.equal (null, err);

from read, it's saying have connection db in use. close after insert/update everytime.

any advice?

i wouldn't calling mongoclient.connect every time. that's causing ton of connections open , close time overloading mongo. should let mongoclient manage connection pool. change store db object mongoclient.connect maybe in init file add like

//store outside init accessible other functions //this use access database var db;  //add init function mongoclient.connect(url, function(err, database){     db = database; } 

then in functions add , update use db object stored update collections , won't need keep opening connections. can drop mongoclient.connect code , don't call db.close() since connections being shared object let mongoclient manage them.


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -