Personal Library Project Feedbacks

Hello, friends.

So, I’ve finished a project from Quality Assurance. Here’s my link https://repl.it/@IndraSubagja/boilerplate-project-library#routes/api.js

I have two questions.

First, when I use findByIdAndUpdate and $push with callback, I notice that it executes two times. But without callback, the first execution is not returning the updated data. So, I do this

        let book = await Book.findById(bookid)
        if(!book) return res.json("no book exists")

        await Book.findByIdAndUpdate(bookid, {
          $push: {comments: comment},
          $inc: {commentcount: 1}
        })

        await Book.findById(bookid, (err, data) => {
          res.json(data)
        })

Is there any simpler way to achieve this?

And second one is in functional_tests.js test. Sometimes, it doesn’t pass and sometimes after pass all the tests, my repl suddenly disconnect and can’t submit it to freecodecamp test. What might wrong?

Incase anyone else sees this the docs for findByIdAndUpdate in mongoose has options you need to set before the callback to return the modified document

[options.new=false] «Boolean» By default, findByIdAndUpdate()returns the document as it was **before**updatewas applied. If you setnew: true,findOneAndUpdate()will instead give you the object afterupdatewas applied. To change the default totrue, usemongoose.set(‘returnOriginal’, false); .