Exercise Tracker CANNOT PASS

Tell us what’s happening:
Hello guys, I need a bit of help here. It’s getting a little frustrating that what ever i do, i cannot pass the following requirements to this challenge, yet the code seems to be working properly. I’d appreciate any help you can give me.

  1. You can POST to /api/users/:_id/exercises with form data description , duration , and optionally date . If no date is supplied, the current date will be used. The response returned will be the user object with the exercise fields added.

  2. You can make a GET request to /api/users/:_id/logs to retrieve a full exercise log of any user. The returned response will be the user object with a log array of all the exercises added. Each log item has the description , duration , and date properties.

Your project link(s)

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

Your browser information:

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

Challenge: Exercise Tracker

Link to the challenge:

I noticed an inconsistency in schema definition.

You declared Exercise as

const exerciseSchema = new Schema({
  userId: String,
  //username: String,
  date: Date,
  duration: { type: Number, required: true },
  description: { type: String, required: true }

But later in your code you have

 const username = data.username;
      const newExercise = new Exercise({userId, username,
 "date": date.toDateString(), duration, description});

      newExercise.save((err, data)=>{
     . . .
        res.json({"_id": userId, username, "date": date.toDateString(), duration, description});

What is your userId ?

It might be logically cleaner to embed the ExerciseSchema (that just has description, duration, and date) inside the User schema like

const UserSchema = new Schema({
 . . .
 exercises: [ExerciseSchema]

and have just the user model. Since exercises won’t exist without an owning user, there’s really no need for a separate exercise model.

1 Like

Dear twotani,
Thank you for your interest in my topic. userId in exercise is actually the “_id” from PersonSchema; meaning every exercise in the schema has its own unique “_id” (not that it make any difference). But I am apt for having users and their properties separate from each other.
However, that is not the issue. The returned object (res.json), is working according to the given example by the FCC; clean or unclean, it works accordingly to said example. I’d appreciate it if you check it out and see the response. And yet I have no idea why it does not pass. You can see the results which fcc is receiving from my server in the console.


I’m not sure at all because when I did that issue tracker I was using other routes. It seems the criteria have changed but I do remember that I could not just enter the userid as a string. You have to use a function that returns the id.
const {ObjectId} = require(‘mongodb’)
and then ObjectId(idstring) ;

I really don’t know if that is going to resolve your issue but can you try this out first?


1 Like

Dear mientje,
Yes, the criteria have changed but that is not the issue. The code can perfectly read URL queries and successfully finds them in the database. Also, the “JSON response” that it sends is correct according to the tests. You can try it and you’ll see the query and the response in the console and the webpage. After monitoring what FCC sends and the response it gets, I’m still wondering what’s wrong with the code.

I know I’ve seen it as well. Have you tried use the ObjectId function? If it doesn’t work we can rule that one out.


Your GET route is failing because you are returning an object containing logs, not log.

Your POST route is failing because you are returning a date of 1990-01-02 and the test is expecting 1990-01-01 (from the source). This looks like a time zone issue to me but running on repl.it, the client (fCC) and server (repl.it) should both be in UTC so that shouldn’t matter. So, do a quick check for anything that might be messing with the timezone in your code or some other issue that would make the fCC server and your code believe they are on different sides of the date line. Otherwise, try manipulating the date in UTC or try to determine the timezone offset and alter the date to be correct.

1 Like

Dear jeremy.a.gray,
Sincerely, LOVE YOU. Changed logs to log , and it immediately passed all but the You can POST to /api/users/:_id/exercises with form data description, duration, and optionally date. . That typo wasted 3 days !!!
Still got nowhere with post thing though.

YAAAYYYYY! Thanks everyone. Found the problem of You can POST to /api/users/:_id/exercises with form data description, duration, and optionally date..

It was because of QUOTES!!! I was returning "duration": "60" instead of "duration": 60.
Anyways, thanks for all your help and insights.

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