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 o
Aggregate
method returns an array; this is the defined behavior. If you want to adapt this behavior to your way, you can either re-create your own aggregate function; or deal with the array at every call; like :
async function aggregate(model, func) {
const aggregateObject = func(News.aggregate());
const ret = await aggregateObject.exec();
// Deal with the fact there is no answer
if (ret && ret.length) {
return ret[0];
}
return false;
}
const directData = await aggregate(News, (aggregateObj) => {
return aggregateObj
.match(...)
.project(...);
});