I’m trying to compare, sort, filter, etc. arrays of MongoDB ObjectIDs as well as sort documents based on an arrays. My main question is: should I use ObjectID.equals() or is it okay to convert them all to strings, use native comparisons like indexOf, and convert them back? Does it matter?
My specific use case: a user can save posts to a list. I save this as an array of ObjectIDs user.saves. I want to retrieve the first 25 posts in order, so I query {_id: {$in: user.saves.slice(0, 25)}}. How would you sort retrieved documents?
solution: