[英]No document found for query xxx on model xxx
I get the error you can read it from the title.我收到错误,您可以从标题中读取它。 It appears whenever i try to
.save()
a document.每当我尝试
.save()
文档时,它就会出现。
let [post] = (
await User.findOneAndUpdate(
{ _id: USER_ID },
{
$push: {
posts: {
title,
content,
userId: USER_ID,
titleUrl,
thumbnail: {
webp: WEBP_PATH,
jpeg: JPEG_PATH,
placeholder: PLACEHOLDER
}
}
}
},
{ new: true }
)
).posts.slice(-1);
let newBlog = new Blog(post);
await newBlog.save();
What i tried:我尝试了什么:
newBlog.update()
no error appeard, but also no change. newBlog.update()
没有出现错误,也没有变化。
I also tried to set a different version key at my model like { versionKey: "_someKey"}
no success.我还尝试在我的 model 上设置不同的版本密钥,例如
{ versionKey: "_someKey"}
没有成功。
What could it be?会是什么呢?
await Blog.create(post)
also didnt work. await Blog.create(post)
也没有工作。 Same error.同样的错误。
For the people that are in the same situation, my solution was adding .lean()
at the end of the query对于处于相同情况的人,我的解决方案是在查询末尾添加
.lean()
let [post] = (
await User.findOneAndUpdate(
{ _id: USER_ID },
{
$push: {
posts: {
title,
content,
userId: USER_ID,
titleUrl,
thumbnail: {
webp: WEBP_PATH,
jpeg: JPEG_PATH,
placeholder: PLACEHOLDER
}
}
}
},
{ new: true }
).lean()
).posts.slice(-1);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.