Within my Post
model, I have an array called likes
that contains the ObjectId
of users who liked the Post. My goal is to sort Posts based on the number of likes they have received.
I've experimented with using $size
, $sort
, and aggregate
, but so far my attempts haven't been successful. Is it possible to use $size
within $sort
? What would be the correct method for achieving this? And is there a specific approach when working with mongoose?