Question about transactional operations in Node js

To my knowledge that, Couchbase doesn’t currently support transactions on the DB level, and the most promising way to keep ACID seems to using single document with nested object. But I still wonder if there is best practice to accomplish “transactions” on the application level if I have to keep things a little more separated. let say we will need to store “question” and “answer” objects that each question will have an array of ids to links to answers, and I am using node js SDK. I will probably end up having code like this.

var answer = {id : “answer_1”, content: “answer”}
bucket.insert(“answer_1”, answer, function(){
bucket.mutateIn(‘questoin_1’).upsert(‘answers’, [answer.id], true).execute…
})

the potential problem with this approach is that if the first request succeed and the second one failed, we will end up having an answer object that we will not be able to access. So any thought on this? Thanks.

Hey @jgue,

In the case that your second query fails, you could make an attempt to remove the first document. Unfortunately, there are some edge cases where the server has failed between the requests, and the only solution would be to perform a batch clean-up job at a later time.

Cheers, Brett

Yeah, I think it makes sense, thanks for helping.