【问题标题】:CastError: Cast to ObjectId failed for value " ObjectId" (type string) at path "_id" for model "Contact"CastError:模型“Contact”的路径“_id”处的值“ObjectId”(类型字符串)转换为 ObjectId 失败
【发布时间】:2021-09-06 04:31:06
【问题描述】:

我试图做的是使用 findByIdAndDelete() 函数从数据库中删除一个项目,而我遇到的问题是 Here is a image of the error(Please ignore all the other things)

在终端上显示的第一个错误旁边还有另一个错误

Both the errors are coming togehter

任何帮助将不胜感激。

【问题讨论】:

  • _id 开头有一个空格。难道是_id是手动添加的,不是自动生成的?
  • @masquerade817 是的,是手动添加的。

标签: mongodb mongoose robo3t


【解决方案1】:

这个id前面有个“”,试试去掉,using id.replace(' ','')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-09-29
    • 2021-12-04
    • 2020-11-19
    • 2021-07-04
    • 2017-08-18
    • 2014-06-20
    • 2020-12-10
    相关资源
    最近更新 更多