MongoDB can't update document because _id is string, not ObjectId

岁酱吖の 提交于 2019-12-03 15:08:10

Because you can't modify the _id field, a better approach is to simply remove the that field from your map object instead of converting it to an ObjectId.

So this:

delete map._id;

instead of this:

map._id = new ObjectID.createFromHexString( map._id);

If you want to return the updated object like you're attempting with res.send(map);, you should be using findAndModify instead of update so you have access to the resulting doc and not just what was posted.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!