【发布时间】:2015-02-09 06:17:25
【问题描述】:
一个快速的:
当我推送更新时,为什么 Mongoose 会更改/升级文档的 _id 字段? 这是预期的行为吗?
谢谢。
这是我在 PUT 路由中使用的更新,它成功返回了更新后的模型,但不幸的是为 doc 提供了一个新的 _id
Document.findById(req.params.doc_id, function (err, doc) {
if (err)
res.send(err)
// Do some subdoc stuff here …
doc.save(function (err) {
if (!err) {
console.log('Success!');
res.json(doc);
} else {
console.log(err);
}
});
});
【问题讨论】:
-
你确定它实际上是一个更新吗?它不应该改变_id。使用一些代码会更容易弄清楚。
-
抱歉有人投了你的票,不是我。