Before starting to use aggregate in order to create a timestamp of the document, I was using findOne so I could get a single object but now I'm getting an array with a single object. Is it possible to make the query return a single object instead of an array? Thank you in advance.
Query that I'm using:
News.aggregate()
.match({ '_id': n })
.project({ 'title': true, 'text': true, 'timestamp': { '$subtract': ['$date', new Date('1970-01-01')] } })
What is returning:
[
{
"_id": "5b9650beae847b1e5866cace",
"title": "Notícia 2",
"text": "Texto da Notícia 2",
"timestamp": 1543807353257
}
]
What I'd like to get returned:
{
"_id": "5b9650beae847b1e5866cace",
"title": "Notícia 2",
"text": "Texto da Notícia 2",
"timestamp": 1543807353257
}
$unwindoperator will help here...