Initially i had:
db.collection(process.env.MESSAGES_COLLECTION).find(req.queryValues).sort({_id:-1}).limit(req.limit)
I've tried:
db.collection(process.env.MESSAGES_COLLECTION).find(req.queryValues).aggregate([
{$sort: {_id: -1}},
{ $limit: req.limit},
{$sort: {_id: 1}}])
But i got an error:
TypeError: db.collection(...).find(...).aggregate is not a function
If i try:
db.collection(process.env.MESSAGES_COLLECTION).aggregate([
{$find: req.queryValues},
{$sort: {_id: -1}},
{ $limit: req.limit},
{$sort: {_id: 1}}])
I get an empty array.