JSON can't add key and value pair?

I’m doing the API and microservices challenge #3, the exercise tracker.

I need to return an object with an array that’s in MongoDB and add a key-value pair “count” to the object.

This is my code

app.get("/api/exercise/log", (req,res) => {
  User.findById(req.query.userId)
    .select({__v: 0, _id: 0, username: 0})
    .exec((err, docs) => {
      if (!err) {
        docs.count = docs.log.length;
        res.json(docs)
      }
  })
})

For some reason, docs.count is not being added, the value it’s being assigned to exists, it’s 6, but I also tried button the value myself and tried using the notation instead of the dot notation, none of those worked.

This is the structure of “docs”

var docs = {
   log: [
      {
         duration: 10,
         date: "Sun Jan 03 2021",
         description: "desc"
      }
   ],
   count: 1 -- this is where count needs to be added, but I can't add it for some reason
}

Is it returning a response? Are you hitting an error? You do not have a catch block in your code to determine whether you’re actually running into an error. Try adding a catch block and logging to the console.

      if (!err) {
        docs.count = docs.log.length;
        res.json(docs)
      }  else {
          console.log('[ERROR] - Retrieving docs :: ', err)
      }

I had a console.log between res.json and docs.count, it logged the “normal” docs, without the count.