简体   繁体   English

在 model xxx 上找不到查询 xxx 的文档

[英]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.

相关问题 ng-model =“ xxx”和value =“ {{xxx}}”之间的区别? - Difference between ng-model=“xxx” and value=“{{xxx}}”? document.getElementById('xxx')显示为空 - document.getElementById('xxx') showing null 将js编号转换为xxx xxx xxx,xx? - convert js number to xxx xxx xxx ,xx? xxxx.xxx.xxx 的正则表达式 - Regex for xxxx.xxx.xxx 异常:服务电子表格在访问 ID 为 XXX 的文档时超时 - Exception: Service Spreadsheets timed out while accessing document with id XXX 服务电子表格在访问 ID 为 xxx 的文档时失败 - Service Spreadsheets failed while accessing document with ID xxx document.getElementById(“ xxx”)。name =“ sample”在Firefox中不起作用,但在IE中起作用 - document.getElementById(“xxx”).name = “sample” not working in firefox but works in IE AngularJS:修改带有'= xxx'隔离范围的指令中父范围的模型吗? - AngularJS : Modify model of parent scope in a directive with '=xxx' isolate scope? Typescript导入一个React js组件,该组件由我自己编写并出现了d.ts文件。找不到模块:无法解析“ xxx”中的“ xxx” - Typescript import a React js component which d.ts file writed by myself and occured Module not found: Can't resolve 'xxx' in 'xxx' PHP 正则表达式 on (xxx) xxx-xxxx - PHP Regex on (xxx) xxx-xxxx
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM