Digital Developer Conference: a FREE half-day online conference focused on AI & Cloud – North America: Nov 2 – India: Nov 9 – Europe: Nov 14 – Asia Nov 23 Register now

Close outline
  • United States
IBM?
  • Site map
IBM?
  • Marketplace

  • Close
    Search
  • Sign in
    • Sign in
    • Register
  • IBM Navigation
IBM Developer Answers
  • Spaces
    • Blockchain
    • IBM Cloud platform
    • Internet of Things
    • Predictive Analytics
    • Watson
    • See all spaces
  • Tags
  • Users
  • Badges
  • FAQ
  • Help
Close

Name

Community

  • Learn
  • Develop
  • Connect

Discover IBM

  • ConnectMarketplace
  • Products
  • Services
  • Industries
  • Careers
  • Partners
  • Support
10.190.13.195

Refine your search by using the following advanced search options.

Criteria Usage
Questions with keyword1 or keyword2 keyword1 keyword2
Questions with a mandatory word, e.g. keyword2 keyword1 +keyword2
Questions excluding a word, e.g. keyword2 keyword1 -keyword2
Questions with keyword(s) and a specific tag keyword1 [tag1]
Questions with keyword(s) and either of two or more specific tags keyword1 [tag1] [tag2]
To search for all posts by a user or all posts with a specific tag, start typing and choose from the suggestion list. Do not use a plus or minus sign with a tag, e.g., +[tag1].
  • Ask a question

My BlueMix node.js + mongodb backend fails after some requests

2700072SDH gravatar image
Question by DGualda  (65) | Mar 28, 2014 at 11:11 AM node.jsmongodbibmcloud

Hi, I have a backend published and working in BlueMix.

Here is its URL: http://crmbackend.ng.bluemix.net/customer/list

After calling this URL a few times, the service fails, and It stops working.

If I go to the log, into BlueMix it doesn't work.

Here is the code for request above:


//Lists all customers
exports.list_customer = function (req, res) { db.connect(mongo.url, function (err, conn) { var collection = conn.collection('customers');

    // list messages
collection.find().toArray(function (err2, items) {
res.send(items);
});
});

};

Thanks in advance.

SteveKinder
pwagstro

People who like this

  0
Comment
10 |3000 characters needed characters left characters exceeded
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster

3 answers

  • Sort: 
110000HUHT gravatar image
Accepted answer

Answer by SteveKinder (566) | Mar 28, 2014 at 11:34 AM

Perhaps you are running out of connections? The community Mongo service has a connection limit of 100 connections... You might try closing or ending your connection and see if your app becomes more reliable?

Comment
pwagstro

People who like this

  1   Show 1   Share
10 |3000 characters needed characters left characters exceeded
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
2700072SDH gravatar image DGualda (65)   Mar 28, 2014 at 01:11 PM 0
Share

Thanks for your help. Full solution has been attached to this thread

270006CP81 gravatar image

Answer by Andrew Huffman (343) | Mar 28, 2014 at 11:48 AM

Without an indication as to what the error was it'd be hard to determine the issue. Can you add a log statement in your callback function?

//Lists all customers exports.list_customer = function (req, res) { db.connect(mongo.url, function (err, conn) { if(err) { console.log("Error connecting: "+err) } else { var collection = conn.collection('customers');

// list messages collection.find().toArray(function (err, items) { if (err) { console.log("Error on find: "+ err); } else { res.send(items); } }); }); };

Comment
SteveKinder

People who like this

  1   Show 1   Share
10 |3000 characters needed characters left characters exceeded
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
2700072SDH gravatar image DGualda (65)   Mar 28, 2014 at 01:11 PM 0
Share

Thanks for your help. Full solution has been attached to this thread

2700072SDH gravatar image

Answer by DGualda (65) | Mar 28, 2014 at 01:09 PM

Hi guys, It seems the reason was the 100 mongodb connections.

To simulate this fact in local I started my local mongodb like: mongod.exe --maxConns 100

The solution for release connections is:

//Lists all customers

exports.list_customer = function (req, res) { db.connect(mongo.url, function (err, conn) { var collection = conn.collection('customers');

    // list messages
collection.find().toArray(function (err, items) {
if (err) {
console.log("Error on find: " + err);
} else {
res.send(items);
conn.close();
}
}
);
});

};

Thank you very much for your help.

Comment
SteveKinder

People who like this

  1   Show 1   Share
10 |3000 characters needed characters left characters exceeded
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
270002CGBR gravatar image Patrick Mueller (1866) ♦   Apr 13, 2014 at 11:57 PM 0
Share

DGualda, you may want to just keep the connection open for the life-time of the server. Presumably you'll be using it often, so opening and closing it all the time is just extra work.

See: http://stackoverflow.com/a/14464750

Follow this question

No one has followed this question yet.

Answers

Answers & comments

Related questions

Deploying an app using MongoLabs instead of MongoDB Service 3 Answers

I get a service broker error when I try to delete an app 7 Answers

Node.js BlueMix Applikation - Post Request 10 Answers

I am unable to push my Node.js project with mongodb backend on Bluemix 2 Answers

MongoDB problem on Bluemix/NodeJS. Application not start. 2 Answers

  • Contact
  • Privacy
  • IBM Developer Terms of use
  • Accessibility
  • Report Abuse
  • Cookie Preferences

Powered by AnswerHub

Authentication check. Please ignore.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • API Connect
  • Analytic Hybrid Cloud Core
  • Application Performance Management
  • Appsecdev
  • BPM
  • Blockchain
  • Business Transaction Intelligence
  • CAPI
  • CAPI SNAP
  • CICS
  • Cloud Analytics
  • Cloud Automation
  • Cloud Object Storage
  • Cloud marketplace
  • Collaboration
  • Content Services (ECM)
  • Continuous Testing
  • Courses
  • Customer Experience Analytics
  • DB2 LUW
  • Data and AI
  • DataPower
  • Decision Optimization
  • DevOps Build
  • DevOps Services
  • Developers IBM MX
  • Digital Commerce
  • Digital Experience
  • Finance
  • Global Entrepreneur Program
  • Hadoop
  • Hybrid Cloud Core
  • Hyper Protect
  • IBM Cloud platform
  • IBM Design
  • IBM Forms Experience Builder
  • IBM Maximo Developer
  • IBM StoredIQ
  • IBM StoredIQ-Cartridges
  • IIDR
  • ITOA
  • InformationServer
  • Integration Bus
  • Internet of Things
  • Kenexa
  • Linux on Power
  • LinuxONE
  • MDM
  • Mainframe
  • Messaging
  • Node.js
  • ODM
  • Open
  • PartnerWorld Developer Support
  • PowerAI
  • PowerVC
  • Predictive Analytics
  • Product Insights
  • PureData for Analytics
  • Push
  • QRadar App Development
  • Run Book Automation
  • Search Insights
  • Security Core
  • Storage
  • Storage Core
  • Streamsdev
  • Supply Chain Business Network
  • Supply Chain Insights
  • Swift
  • UBX Capture
  • Universal Behavior Exchange
  • UrbanCode
  • WASdev
  • WSRR
  • Watson
  • Watson Campaign Automation
  • Watson Content Hub
  • Watson Marketing Insights
  • dW Answers Help
  • dW Premium
  • developerWorks Sandbox
  • developerWorks Team
  • Watson Health
  • More
  • Tags
  • Questions
  • Users
  • Badges