[英]Displaying result from MongoDB collection with Pug
I have a MongoDB collection and it's structure like this;我有一个MongoDB集合,它的结构是这样的;
{
"_id": "4rc4f9653fc4ff04dd7d31h6",
"title": "my title",
"url": "https://myurl.com",
"author": "john",
"created": {
"$date": "2020-05-20T04:12:47.457Z"
},
"vote": 1619
}
And i have below pug
layout;我有以下pug
布局;
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
This is working fine and the outcome is like this;这工作正常,结果是这样的;
mytitle , john, 1619我的头衔,约翰,1619
I would like to add date field as well.我也想添加日期字段。 So my final outcome should be like this;所以我的最终结果应该是这样的;
mytitle , john, 1619, 2020-05-20 mytitle , 约翰, 1619, 2020-05-20
I tried to add created
field as shown below but this is not bringing any value for created.我尝试添加created
字段,如下所示,但这并没有为 created 带来任何价值。 Any idea what am i missing here?知道我在这里缺少什么吗?
a(href=entry.url, target='new')= entry.title
|,
span.text-success=entry.author
|,
span.text-success=entry.vote
|,
span.text-success=entry.created
In your data, created
is an object, not a date string.在您的数据中, created
是 object,而不是日期字符串。 To access the date string, you'd need to do:要访问日期字符串,您需要执行以下操作:
span.text-success= entry.created['$date']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.