通过 id 更新在猫鼬中不起作用 [英] update by id not working in mongoose
问题描述
我有一个代码,我在其中使用 mongoose 和架构建立新连接.连接正确,我也从集合中获取属性.之后我想在我的收藏中更新,但那不起作用..我有以下代码
I have a code in which i am making a new connection using mongoose and using a schema also. The connection is made properly and im also getting the attributes from the collection. After that i want to update in my collection, and that is not working.. I have following code
console.log("id : "+content._id);
Alert.findByIdAndUpdate(content._id, {
$set: {
status: true
}
}, function(error, result) {
console.log(result);
if (error) console.log(error);
else {
console.log('Alert updated');
}
});
它显示警报已更新但状态仍然是错误的..
It shows alert updated but status remains false..
result for 1st console is
id : 55096a5f91169c8e1673af20;
and 2nd console is
Alert updated
提前致谢和问候
推荐答案
你的代码看起来很完美,id 看起来是正确的,你的代码没有返回任何错误,所以你检查了你的架构,看看它是否包含状态"领域?
Your code looks perfect, the id looks like it's correct and your code don't return any errors, so have you checked your schema to see if it contains the "status" field?
看起来您可以创建和编辑具有两边不相等的架构的新文档,应用数据层.
Looks like you can create and edit new documents with a schema that is not equal on both sides, application an data layers.
更多信息:https://github.com/Automattic/mongoose/issues/1060
这篇关于通过 id 更新在猫鼬中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!