Given the schema:

```
{
    widgets: [{
        widget: {type: mongoose.Schema.Types.ObjectId, ref: 'widget'},
        count: {type: Number}
    }]
}

```

and an application route where:

1. User attempts to add a new widget into the widgets array of an existing document.
2. We check that the widget being added meets some requirements.
3. We add the widget to the document and save the document.

**In this setup, if I have 2 parallel requests to perform the same action, both checks in number 2 pass and the document is saved with 2 copies of the widget, even though that's "illegal" in my business logic.**

The async flow looks like:

1. Req1 hits route, loads existing doc
2. Req2 hits route, loads existing doc
3. Req1 checks doc conditions
4. Req2 checks doc conditions
5. Req1 embeds the new widget, saves doc
6. Req2 embeds the new widget, saves doc

I thought that document versioning (`__v`) would solve this for me as it has in the past, but apparently I never understood this to begin with because both requests are running sequentially and my debugger shows that the version of the document is X in both pre-save states, and X+1 in the post-save state. I don't understand why that doesn't throw a version error.

I think that this is an asynchronous problem to solve, not necessarily strictly Mongoose, and have tagged as such. 

**Edit:** This works but seems remarkably verbose:

```
model
    .findOneAndUpdate({
        _id: doc._id,
        __v: doc.__v
    },
    {
        $push: {
            widgets: {
                widget: widget_id,
                qty: 1
            }
        },
        $inc: {
            __v: 1
        }
    },
    function(err, doc) {
        // ...
    });

```

Also, it is unfortunate that I can't alter my existing doc and then run the `save()` method on it. 

My searching found [this bug](https://github.com/Automattic/mongoose/issues/1265) where the `versionKey` didn't increment automatically when using this method. I suppose I really don't understand `versionKey` properly!