从Node Js和Mongoose中的应用程序收到的响应不完整 [英] Incomplete response received from application in Node Js and Mongoose

查看:74
本文介绍了从Node Js和Mongoose中的应用程序收到的响应不完整的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 cPanel 将api rest安装在主机中。路由工作正常,并且数据库已连接。问题是当我需要使用任何猫鼬方法时,即 model.find({}),响应为

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

对于其他路由,这些路由不会从数据库,使用 json 格式完美运行。

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

推荐答案

您无法运行MongoDB在共享主机上。 请参考此主题。

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

您可以使用免费的云服务,例如Heroku https:// heroku.com 或AWS或Azure等更复杂的网站。如果必须进行共享托管部署,则可以选择使用外部MongoDB实例。获取MongoDB实例的最简单方法是使用MongoDB Atlas。有一个免费的沙箱用于开发。

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. 转到 https://www.mongodb.com/cloud/atlas ,然后登录/创建帐户

  2. 点击建立集群。将其设置为免费实例的第0层。

  3. 创建集群后,单击连接,然后选择连接应用程序

  4. 复制mongoDB URI并将其粘贴到包含 mongoose.connect(mongoDBAtlasURIhere,{useNewUrlParser:true,useUnifiedTopology:true})之类的代码中

  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})

Node JS完整教程示例: https://medium.com/@sergio13prez/connecting-to-mongodb-atlas-d1381f184369

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

希望这会有所帮助。

这篇关于从Node Js和Mongoose中的应用程序收到的响应不完整的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆