I have a schema as follows:
var answerSchema = new mongoose.Schema({
username: {
type: String,
unique: true,
required: true
}
)
mongoose.model("Answer", answerSchema)
and in another file I have:
var Answer = mongoose.model("Answer")
router.put("/test", function (req, res){
const query = { _id: "5fe656077ddb2a4e1a91d808"}
const update = { username: 'test' }
const options = {
new: true,
upsert: true,
setDefaultsOnInsert: true
}
Answer.findOneAndUpdate(query, update, options, function(error, doc) {
if(error){
res.send(error.message)
}
else{
res.send('successfully saved.')
}
})
})
Currently in the mongo shell, I can run db.answers.find().pretty() and it gives me:
{
"_id" : ObjectId("5fe656077ddb2a4e1a91d808"),
"username" : "aaaa",
"__v" : 0
}
However, when I use POSTMAN to access the "/test" URL, I get an error "Retryable writes are not supported". I know documentdb doesn't support retryable writes, but how does this FindOneAndUpdate require retryable writes? I also tried using set() and save() with findOne(), and the findOne() works fine, but the set() throws the same error. Did I miss something here?