Exercise tracker jul 2021 test 7 don't pass

Hi, I can’t pass test 7
Could anyone help me, please …

Here my code

app.get('/api/users/:_id/logs', function(req, res) {
 
let { _id, from, to, limit } = req.query;
_id = req.params._id;
Person.findById(_id, (error, data) => {
  
if(!data) {
  res.send("Unknown User")
} else {
  const username = data.username;
console.log({"from": from, "to": to, "limit": limit})
    let fromDate = new Date(from);
  fromDate = moment(fromDate).format("YYYY-MM-DD");
    let toDate = new Date(to);
  toDate = moment(toDate).format("YYYY-MM-DD");

  Info.find({_id}, {date: {$gte: fromDate, $lte: toDate}}).select(["_id", "description", "duration", "date"]).limit(+limit).exec((error, data) => {
    let logData = data.map(exer => {
      let formatDate = new Date(exer.date)
      formatDate = moment(formatDate).format("YYYY-MM-DD");
      return {_id: exer._id, description: exer.description, duration: exer.duration, date: formatDate}
    })

    if(!data) {
      res.json({
        "_id": _id,
        "username": username,
        "count": 0,
        "log": []
      })
    } else {
      res.json({
        "_id": _id,
        "username": username,
        "count": data.length,
        "log": logData
      })
    }
  })
}

})
})

This is my error in console

{ from: undefined, to: undefined, limit: undefined }
{ from: undefined, to: undefined, limit: undefined }
{ MongoError: E11000 duplicate key error collection: db1.infos index: _id_ dup key: { _id: "60de1eaec6c5b502215cff40" }
    at Function.create (/rbd/pnpm-volume/d811e03c-d00e-4d47-a601-489765cf0003/node_modules/.registry.npmjs.org/mongodb/3.6.8/node_modules/mongodb/lib/core/error.js:57:12)
    at toError (/rbd/pnpm-volume/d811e03c-d00e-4d47-a601-489765cf0003/node_modules/.registry.npmjs.org/mongodb/3.6.8/node_modules/mongodb/lib/utils.js:130:22)
    at coll.s.topology.insert (/rbd/pnpm-volume/d811e03c-d00e-4d47-a601-489765cf0003/node_modules/.registry.npmjs.org/mongodb/3.6.8/node_modules/mongodb/lib/operations/common_functions.js:258:39)
    at handler (/rbd/pnpm-volume/d811e03c-d00e-4d47-a601-489765cf0003/node_modules/.registry.npmjs.org/mongodb/3.6.8/node_modules/mongodb/lib/core/sdam/topology.js:943:24)
    at fn (/rbd/pnpm-volume/d811e03c-d00e-4d47-a601-489765cf0003/node_modules/.registry.npmjs.org/mongodb/3.6.8/node_modules/mongodb/lib/cmap/connection_pool.js:350:13)
    at handleOperationResult (/rbd/pnpm-volume/d811e03c-d00e-4d47-a601-489765cf0003/node_modules/.registry.npmjs.org/mongodb/3.6.8/node_modules/mongodb/lib/core/sdam/server.js:558:5)
    at MessageStream.messageHandler (/rbd/pnpm-volume/d811e03c-d00e-4d47-a601-489765cf0003/node_modules/.registry.npmjs.org/mongodb/3.6.8/node_modules/mongodb/lib/cmap/connection.js:281:5)
    at MessageStream.emit (events.js:198:13)
    at processIncomingData (/rbd/pnpm-volume/d811e03c-d00e-4d47-a601-489765cf0003/node_modules/.registry.npmjs.org/mongodb/3.6.8/node_modules/mongodb/lib/cmap/message_stream.js:144:12)
    at MessageStream._write (/rbd/pnpm-volume/d811e03c-d00e-4d47-a601-489765cf0003/node_modules/.registry.npmjs.org/mongodb/3.6.8/node_modules/mongodb/lib/cmap/message_stream.js:42:5)
    at doWrite (_stream_writable.js:415:12)
    at writeOrBuffer (_stream_writable.js:399:5)
    at MessageStream.Writable.write (_stream_writable.js:299:11)
    at TLSSocket.ondata (_stream_readable.js:710:20)
    at TLSSocket.emit (events.js:198:13)
    at addChunk (_stream_readable.js:288:12)
  driver: true,
  name: 'MongoError',
  index: 0,
  code: 11000,
  keyPattern: { _id: 1 },
  keyValue: { _id: '60de1eaec6c5b502215cff40' } }

Image all test passed except number 7

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

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