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?