'mongoose schema optimisticConcurrency option on subdocuemnt

I'm trying to implement optimisticConcurrency on mongoose Subdocument and i cant get to make it work.

consider

const SchemaA = new Schema({

    keyA: String,

    subdocA: new Schema({
                 subdocA_a: String,
                 subdocA_b:String 
             },{ optimisticConcurrency: true })
})

I wish to be able to update subdocA.subdocA_a only if subdocA.subdocA_b did not change (i dont mind if keyA changed).

i followed the docs on how to implement optimisticConcurrency here, without any success.

when i moved the optimisticConcurrency option to the parent Schema i.e:

const SchemaA = new Schema({

    keyA: String,

    subdocA: new Schema({
                 subdocA_a: String,
                 subdocA_b:String 
             })
},{ optimisticConcurrency: true })  <---------------

it worked. but i want the Concurrency control ONLY on the subdocument.

so i want to know if optimisticConcurrency can work on subdocument (mongoose docs are not clear about it), and if so, how to make it work.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source