0

I installed my api rest in my hosting using cPanel. The routes work perfect and the db is connected. The problem is when I need to use any mongoose method, i.e. model.find({}), the response is

Incomplete response received from application

For other routes, that don't return any data from the DB, works perfect, using json format.

Sabith
  • 1,628
  • 2
  • 20
  • 38
  • I could fix it. The poblem was the connection from the hosting to Mlab. I asked the hosting to open one port and it worked. – carlos8_alb Dec 04 '19 at 17:43

1 Answers1

0

You cannot run MongoDB on shared hosting. Please refer to this thread..

You can use free cloud service like Heroku https://heroku.com or more sophisticated ones like AWS or Azure. If shared hosting deployment is a must, then an option is use external MongoDB instance. Easiest way to get MongoDB instance is using MongoDB Atlas. There is a free sandbox for development purpose.

To create an instance, follow these steps:

  1. Go to https://www.mongodb.com/cloud/atlas, and login/create account
  2. Click 'build a cluster'. Set it as tier-0 for free instance.
  3. Once the cluster is created, click on connect, then choose 'connect your application'
  4. Copy the mongoDB URI and paste it to your code containing something like mongoose.connect(mongoDBAtlasURIhere, { useNewUrlParser: true, useUnifiedTopology: true})

Example of complete tutorial for Node JS: https://medium.com/@sergio13prez/connecting-to-mongodb-atlas-d1381f184369

Hope this helps.

yogski
  • 181
  • 1
  • 10