javascript - 变量没有状态键,但 var.status 给出字符串

标签 javascript node.js mongoose

它是一个 mongoose/express 应用程序,我有一条这样的路线:

// ..
Posts.find({})
.then(function(posts) {
  var data = _.chain(posts).filter(function(post) {
    if(post.comment) {
      return post.updatedAt <= post.comment.lastCreatedAt;
    } else {
      return true;
    }
  }).each(function(post) {
    if(post.comment) {
      post.status = 'OK';
    } else {
      post.status = 'NOT OK';
    } 
    console.log("post")
    console.log(post)
    console.log("post.status")
    console.log(post.status)
  }).value();   
})
// ..

但是日志是

"post"
{
  _id: ***,
  title: 'test',
  content: 'test',
  user: ***
}
"post.status"
OK

为什么第一个console.log(post)中没有状态?

最佳答案

该帖子是 Document对象,这意味着它有一个自定义 toJSON只产生模式属性和 _id 的方法。

您可以通过 toObject 方法获取文档的对象表示。

关于javascript - 变量没有状态键,但 var.status 给出字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36167252/

相关文章:

javascript - 使用 javascript 而非 jQuery 的简单 ajax 表单

angularjs - 使用 Satellizer.js 注销

node.js - 执行 npm install 或 npm install -g 时出错?

javascript - 在 Node.js 中使用回调的正确方法

node.js - MongoDB更新语句设置其他集合中的值

node.js - mongoose — 检查 ObjectId 是否存在于数组中

mongodb - 查找聚合中的管道在 mongodb 中不起作用

javascript - 你能将 javascript 应用程序封装在 java 容器中吗?

javascript - Chrome 扩展程序 - 注入(inject)脚本时出现 "tab was closed"错误

javascript - 如何将自动对焦设置为选择下拉列表中的输入?