hello everyone.
This seems very straight forward but I can't get it to work so if anyone has any ideas I would greatly appreciate it.
I am running node & mongoDB local. I wrote a basic schema that capture timestamp & ip address. Everything works fine when I don't try to access the database more then once at a time.
I wrote a basic shell script that pings node with requests to add entries to the database every 100 ms and ran 2 instances of the shell script. When both are running mongoose errors out every once and while on mongoose.connect. giving err = { state : 1 } or { state : 2 }
Seems like something is preventing concurrent connections. Is there anything I can do on the mongoose.connect end to make this work better? or do i need to config mongoDB differently? (currently it's latest stable build out of the npm without any config done)
Here is my connection code ( nodejs + express + mongoose ):
var connectDb = function (res, callback) {
mongoose.connect(mongourl);
var db = mongoose.connection;
db.on('error', function (err) {
res.json(500, err);
});
db.once('open', callback);
};
After this code is run the callback creates & adds a new document then closes the connection when done. I get no errors inside the DB when adding documents.
Any thoughts would be greatly appreciated.
Thanks.