Glanced at the code… not a deep dive, but it looks like you are trying to sort the date using a string. A date string won’t likely be able to sort by chronologically, because at that point, its like trying to sort the following chronologically:
“Thursday Nov 14th 1932”
“Saturday Mar 9th 2018”
Trying to sort as a string, S would come before T, but I’m not even sure if JS would perform that kind of sort. If you need to sort your results by date cronologically, you’d need to use date objects.
One of the interesting design choices for this project was how to store the date… store it as a string and just output it, or store it as a date, and convert it to a string to output it… the first seems easier, unless you have to perform date math on it… which to sort you’d need to. If you store the date as a string, to do chronological comparisons I’d think you’d need to convert everything to date objects to get the proper response. I’m not exactly sure how you’d do that in a query.
Anothering interesting design choice was how to store the data in your database. One Schema, Two Schemas with one embedded. It seems that you actually used two schemas, but you didn’t embed one to the other… that means they aren’t tied together. It looks like you use your Users object to determine if the user exists and get the username, and then use that username to look up your Exercise… the problem is, there is no real way to tie a list of exercises to a particular user… like if you had two users that used the same username… they would have a unique id, but when you type your id, you’d get all exercises back for that username, even if they aren’t yours.
I also noticed that your return for api/:_id/logs doesn’t return in the format specified in the challenge page… username/id/count/then array of logs. Yours gave me count then array of logs… but if the tests are passing then maybe thats not a hard requirement.
If you’re passing all but the last test, I don’t think a rewrite would be necessary, but as you’re filtering your log response using a query, you may need to research how you can do that using strings for date, or change so it stores date as a date object… or maybe someone else can see a cleaner fix.
If you do want or end up needing to rewrite your schemas… may want to look into subdocuments (kinda confusing, but kinda simple). Basically it ends up being a single schema, with a field that is an array of another type of schema.
Hope some of that helps. Feel like I’m basically pointing out a few problems without a clear cut solution