Below is my mongoose query along with the router:
router.get('/reportsRegular', function(req,res,next){
Question.find({reports: {$size: {$gt: 0}}, checked: false}).sort({reports: -1}).limit(20).exec(function(err,results){
console.log(results)
res.render('reports', {type: 'regular', user: req.user, reports: results})
})
I encountered an issue with the first find condition. When I change $gt to 1 instead of using it for cases with more than one, it works fine. However, it fails in scenarios where there are multiple items, so I need to use $gt.
Here is a sample JSON document that should match but is not being found:
{
_id: new ObjectId("6212e77aa1e98ae3282a61e6"),
title: 'TOMATOOOOOO',
text: '<p>AAAAAAAAAAAAAAAA</p>',
authorUsername: 'SweetWhite',
dateCreated: 2022-02-21T01:14:34.901Z,
answers: [],
likes: [0],
dislikes: [0],
tag: 'Languages',
views: [1, 'SweetWhite'],
reports: ['SweetWhite'],
checked: false,
reportsNested: [],
__v: 0
}
It should be found as the size of the reports array is greater than zero and the checked value is false. What am I missing here?
Thank you!