Database

[{test:{a1:"a1"}},{test:{b5:"b5"}}]

Query

db.collection.update({test:{a1:"a1"}},[{$set:{test:{a2:"a2"}}}],{upsert:true})

Result