I don’t like the way I’m writing this promise because i feel like there might be better way to write it here is my code
try {
const thread = await newThread.save()
let updatedboard = await Board.findOne({"boardName":board})
const firstUpdate = await Board.findOneAndUpdate({"boardName":board}, {$push:{"threads":thread}, $set:{"totalThreads":updatedboard.threads.length+1}})
updatedboard = await Board.findOne({"boardName":board})
res.send(updatedboard)
}
catch(err) {
console.log(err)
}
First I save my newly created thread model into a document and also store it as a variable (I understand I don’t need to save it here), I then have to find the document so I can reference the document when I’m updating it, this is where i wonder if there is a better method to get the data i need so instead of finding the same document twice i can just find and update it.