You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Mongoose、MongoDB、NodeJS和Express时POST请求无法存数据

Mongoose + MongoDB POST接口报错排查请求

我试过各种解决方案,甚至重写了代码,但还是一直报错。我用Mongoose连接MongoDB搭建了一个简化版项目,在places-controllers.js中导入模型后,通过Postman向http://localhost:5000/api/places/发送POST请求,传入指定测试数据时,每次都会进入错误捕获分支,返回{"status": "error caught"}。我需要让createPlace接口的POST请求正常工作,核心问题应该出在createPlace方法的try-catch逻辑里。

测试数据

{
    "title": "Punta Arena Stfdsfdsfsdfop",
    "description": "One stop Stop. Does not have tr12affic lights.",
    "busrespect": "12ysdfdsfsfes",
    "address": "Avenida Solunna",
    "creator": "52peru soiflsdjf36"
}

涉及的核心文件

  • app.js
  • places-routes.js
  • places-controllers.js
  • models/http-error.js
  • models/place.js

内容的提问来源于stack exchange,提问作者Carlitos

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 04:30:49