Exercise Microservice Challenge - I cannot seem to pass Test 8

Tell us what’s happening:
Hi guys,

I have been trying to figure out what I may be doing wrong here. I am using mongo for this project. I am able to save the exercises to the database, and read the data.

I am also managing to retrieve both the USER for the specific ID entered in the ID field of EXERCISE, and also retrieve the same data that I entered in the fields of EXERCISE.

I am then trying to combine both objects retrieved from Mongo using the Object.assign(). I seem to be doing the job, and then responding to json with the new merged Object.

These lines of code are 130-137 if the data is empty, or 155-162 if the data is correct.

You can see from the json that both objects are merged together and should be displaying what the test requires (unless I have a complete misunderstanding of the test.

Edit 1: I may have been doing a mistake, in which I was reading the exercise info rather than just adding the user info to the exercise input. Made this change and I avoided the problem of having to merge objects, however, still cannot pass the test…

Your project link(s)

solution: https://replit.com/@xondoi/boilerplate-project-exercisetracker

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36

Challenge: Exercise Tracker

Link to the challenge:

I didn’t inspect the database directly to get all the details of what is actually happening in the code, but the problems are down to how you are constructing the IDs you are transmitting and using. You are trying to use count and store that as the userId, but count resets to zero every time the server starts, so I believe you are storing multiple records with different data but the same userId values. MongoDB automatically creates an _id in the record that is unique, so you don’t have to handle IDs and they are unique, even over server restarts (they are time based, partially). Also, you’ll want to look at the differences between find() and findOne() because I think that will help your user lookup implementation.

The easiest solution is to use the MongoDB _id values and not your own. I tried to patch your implementation, but I was unable to do so. The test in question passed when I removed your ID implementation and used the MongoDB _id values.

Hmmm, I will look into this. I wanted to create my own IDs to have a “cleaner” id when I run the tests in exercises.

I will try this out. Thanks.

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