I need to find a user with X _id
and I need the most current weightTracker.date
usually it will be the last one.
I've tried db.user.find({_id:userid}, {weightTracker:1}).sort({"weightTracker.date":-1})
With little success on ordering my results. But most important that always returns all the results and I am only interested in the most current one.
How Could I get the most recent object in weightTracker
given the object's date
in user X?
User
_id
weightTracker[{ manyproperties:menyproperties, date:date}]