问题
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.
回答1:
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:
- Go to https://www.mongodb.com/cloud/atlas, and login/create account
- Click 'build a cluster'. Set it as tier-0 for free instance.
- Once the cluster is created, click on connect, then choose 'connect your application'
- 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.
来源:https://stackoverflow.com/questions/59168547/incomplete-response-received-from-application-in-node-js-and-mongoose