Node.js 使用Pug显示MongoDB集合的结果

Node.js 使用Pug显示MongoDB集合的结果,node.js,mongodb,mongodb-query,pug,Node.js,Mongodb,Mongodb Query,Pug,我有一个MongoDB集合,其结构如下 { "_id": "4rc4f9653fc4ff04dd7d31h6", "title": "my title", "url": "https://myurl.com", "author": "john", "created": { "$date": "2020-05-20T04:12:47.457Z" }, "vote": 1619 } 我有下面的puglayout block c

我有一个MongoDB集合,其结构如下

{
    "_id": "4rc4f9653fc4ff04dd7d31h6",
    "title": "my title",
    "url": "https://myurl.com",
    "author": "john",
    "created": {
        "$date": "2020-05-20T04:12:47.457Z"
    },
    "vote": 1619
}
我有下面的
pug
layout

block content
  h1 #{title}
  ul.list-group
    each entry, i in entries
      li.list-group-item
        a(href=entry.url, target='new')= entry.title
        |, 
        span.text-success=entry.author
        |, 
        span.text-success=entry.vote
这很好,结果是这样的

{
    "_id": "4rc4f9653fc4ff04dd7d31h6",
    "title": "my title",
    "url": "https://myurl.com",
    "author": "john",
    "created": {
        "$date": "2020-05-20T04:12:47.457Z"
    },
    "vote": 1619
}
,约翰,1619

我想添加日期字段以及。所以我的最终结果应该是这样的

{
    "_id": "4rc4f9653fc4ff04dd7d31h6",
    "title": "my title",
    "url": "https://myurl.com",
    "author": "john",
    "created": {
        "$date": "2020-05-20T04:12:47.457Z"
    },
    "vote": 1619
}
,约翰,16192020-05-20

我试图添加
created
字段,如下所示,但这不会为created带来任何价值。你知道我在这里遗漏了什么吗

a(href=entry.url, target='new')= entry.title
|, 
span.text-success=entry.author
|, 
span.text-success=entry.vote
|, 
span.text-success=entry.created

在数据中,创建的
是一个对象,而不是日期字符串。要访问日期字符串,您需要执行以下操作:

span.text-success= entry.created['$date']

这给了我一个错误:“无法读取未定义”的属性“$date”,您正在从
每个
循环中调用它?这是我的app.js,顺便说一下:Entry.aggregate([{$group:{u id:{$url],author:{$first:$author},vote:{$max:$vote},url:{$first:$url},title:{$first:$title}},{$sort:{$vote:$1},{$limit 500}])。exec(函数(错误,条目)…我想知道我是否需要在这里包含日期…是的,否则它不会传递给帕格。