【问题标题】:mongoose cannot detect _id after importmongoose 导入后无法检测到 _id
【发布时间】:2021-01-23 08:39:18
【问题描述】:

如果您从 mongo db 中导出数据,例如 {"_id":"5ee8b4b32af76531cd46d714"} 并且无法使用 Modal.findById(_id);查看完整答案...

【问题讨论】:

    标签: node.js mongodb mongoose schema


    【解决方案1】:

    如果你像从 mongo db 中导出数据

    {"_id":"5ee8b4b32af76531cd46d714"}

    并且很难找到它

    Modal.findById(_id);

    你应该改变你的数据并像这样导入它

    {"_id":{"$oid":"5ee8b4b32af76531cd46d714"}

    让 mongoDB 识别它的 objectId 并通过它找到它

    Model.findById(_id);

    祝你好运。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-24
      • 2016-09-09
      • 2021-02-15
      • 2013-05-02
      • 2015-03-31
      • 2014-01-04
      • 2018-08-17
      • 2015-04-24
      相关资源
      最近更新 更多