The simplest way should be
db.collection.update({versions.v:'some_version'},{"$inc":{"versions.$.count":1}});
This will increase your counter if a version exists, but as MongoDB says, the $ operator cannot be mixed with upsert, so the above request will not result in an insertion if {versions.v:'some_version'} does not work.
A positional operator cannot be combined with a raise because it requires the corresponding array element. If your update results in an insert, then the letter "$" will be used as the field name.
Below are JIRA tickets for upsert support with $. You can vote and see this problem.
Acceleration with the $ -position operator can create bad documents
Support $ positional operator with upsert
Ravi khakhkhar
source share