Exercise Tracker Date filter

Hey there!

I’ve been working for a few days on this project now but unfortunately, I couldn’t pass tests 5 and 7 and I couldn’t figure out why… if someone could help me figure it out… it would be much appreciated

Here’s my replit: https://replit.com/@MidoZZX/boilerplate-project-exercisetracker

all the other requests are correct so you could look at the last app.get one… Thanks in advance!

there seems to be no link between your Person and Exercise models. I can see your Exercise schema has a field userId, but when you create one, you dont pass it to the document, so that param must end blank. When you call Model.find on Exercise, you dont look for the supposed user Id(to call only exercises entitled to the patricular user you wanna get log for).
There are few ways to connect Users and their Exercises documents, i advise you look more into Mongoose docs and topics on the net on that matter. There was even an example within the FCC lessons, which stores some user data in an array and the use of array with the current project is generally a good practice.

Actually, I spend quite a good time looking through the mongoose docs but I don’t think I’m looking at the right places… so if you could please provide links for the needed topics for this project it would be so much appreciated!

One main notion is the so called “subdocuments”- Mongoose v5.12.13: SubDocuments
Another option is to reference documents using the populate()method- Mongoose v5.12.13: Query Population

Those can be a bit overwhelming initially. There are also more standard javascript approaches, when you dont feel skilled enough to do it using the Mongoose inventory, but its not always very practical and you dont have access to the Mongoose powerful tools. For example you could directly store an array of exercise objects in every user document and manipulate it directly with JS, or add a user name/Id to every exercise document and whenever you need a user log, you pull out all exercises containing his name/Id, make an array out of it etc.)

Yeah definitely a bit xD
I tried rewriting the same code I had but with linking the _id I had in the exercise model… and I got the 5th and 6th tests done… now I have the 7th one left… which is just about filtering with date… so if you could help me with that… it would be much appreciated again… Thank you very much for the replies though!

i checked your project code, hoepfully its the updated version. What i noticed is, you overwrite the exercise _id with one you input, and the one you input is the user _id, which is wrong on few levels. First, mongoDB auto-generates and assigns a unique _id prop to every document. Its not good practice to interfere and assign your own _id values, or overwrite existing ones. Im not sure you even manage to do that properly. You try to assign the user _id value to every exercise, but each exercise needs a unique _id. Instead, you can add another prop to your exercise schema, called userId(i beleive you had such initialy) and when you create a new exercise, store the user _id value on that prop, that way the auto-generated exercise _id wont be interefered.
When you try to find all exercises of the particular user, you can simply put as search parameter userId to be equal to the particular user _id and then, you can put additional restrictions on what props to return from every exercise document:

Model.find( {...what you look for}, 'what props to return', callback(err, documentsFound) { ... } )

On the 'what props to return' string you can say '-_id -userId -__v' , which will skip the props _id, userId and __v(this one stores some versioning, again auto-generated by mongo).

I got confused so hard after I tried to edit the _id to userId and now I can’t get 2 more tests done :cry:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.