Exercise Tracker - The date property of any object in the log array... [help]

Hello guys! I have the following problem: The date property of any object in the log array that is returned from GET /api/users/:id/logs should be a string… Use the dateString format of the Date API.


All tests pass except this one, however, it looks like my code is returning what is asked.
Here is the link to my project: Invitation to collaborate on Replit - Replit

My code:

const express = require('express')
const app = express()
const cors = require('cors')
const mongoose = require('mongoose')
const { Schema } = require('mongoose')
const bodyParser = require('body-parser')
require('dotenv').config()
const MONGO_URL = process.env.MONGO_URL;
mongoose.connect(MONGO_URL);
const userSchema = new Schema({
  username: {
    type: String,
    required: true
  },
  log: [{
    description: String,
    duration: Number,
    date: String
  }],
  count: Number
});
const User = mongoose.model('User', userSchema);
app.use(cors())
app.use(bodyParser.urlencoded({ extended: false }))
app.use(express.static('public'))
app.get('/', (req, res) => {
  res.sendFile(__dirname + '/views/index.html')
});



app.route('/api/users')
    .post((req, res) => {
      const username = req.body.username
      const user = new User({ username, count: 0 })
      user.save((err, data) => {
        if (err) {
          res.json( { error: err })
        }
        res.json(data)
      })
    })
    .get((req, res) => {
      User.find((err, data) => {
        if (data) {
          res.json(data)
        }
      })
    })
app.post('/api/users/:_id/exercises', (req, res) => {
  const { description } = req.body
  const duration = parseInt(req.body.duration)
  let date = req.body.date ? new Date(req.body.date).toDateString() : new Date().toDateString()

  const id = req.params._id;
  const exercise = {
        description,
        duration,
        date,        
  }
  
  User.findByIdAndUpdate(id, { 
    $push: { log: {...exercise, date: (new Date(exercise.date).toISOString().split('T')[0])} }, 
    $inc: {count: 1} }, {new: true}, (err, user) => {
    if (user) {
      const updatedExercise = {
        _id: id,
        username: user.username,
        ...exercise
      }
      res.json(updatedExercise)
    }
  })
}) 
app.get('/api/users/:_id/logs', (req, res) => {
  const { from, to, limit } = req.query
  console.log(from, to, limit)
  User.findById(req.params._id, (err, user) => {
    if (user) {      
      if (from || to || limit) {
        const logs = user.log
        const filteredLogs = logs
                .filter(log => {
                  const formattedLogDate = (new Date(log.date)).toISOString().split('T')[0]
                  console.log(formattedLogDate)
                  return true
                })
        console.log(filteredLogs)
        const slicedLogs = limit ? filteredLogs.slice(0, limit) : filteredLogs
        user.log = slicedLogs
        console.log(slicedLogs)
      }
      res.json(user)
    }
    
  })
})


app.get('/mongo-health', (req, res) => {
  res.json( { status: mongoose.connection.readyState })
})



const listener = app.listen(process.env.PORT || 3000, () => {
  console.log('Your app is listening on port ' + listener.address().port)
})

My package.json:

{
	"name": "fcc-exercise-tracker",
	"version": "0.1.0",
	"description": "A REST API project, part of Free Code Camp's curriculum",
	"main": "server.js",
	"scripts": {
		"start": "node server.js"
	},
	"dependencies": {
		"dotenv": "^8.2.0",
		"express": "^4.16.4",
		"cors": "^2.8.5",
		"mongoose": "6.3.1",
		"body-parser": "1.20.0"
	},
	"repository": {
		"url": "https://github.com/freeCodeCamp/boilerplate-project-exercisetracker"
	},
	"license": "MIT",
	"keywords": [
		"node",
		"express"
	]
}

Only thing I notice is that the object returned when creating a log has a different format than the dates returned in /api/user/:id/logs. They both are strings it appears. Maybe the format matters.

{"_id":"626f0876064d4b62289756b0","username":"Dad","description":"dinner","duration":10,"date":"Sun May 01 2022"}
{"_id":"626f0876064d4b62289756b0","username":"Dad","count":1,"log":[{"description":"dinner","duration":10,"date":"2022-05-01","_id":"626f0897064d4b62289756b2"}],"__v":0}

I’m still confused about this, I’ve been trying to fix this part for 1 week now

Take a look at your database and verify the dates are stored in the proper format. If they are , I would say something in your filtering is altering them.

can you see the chat in repl?