Check duplicate in array using key

Hi all,

I want to check duplicate json elements in an array using python sub-document API.

The array contains json key and value. I have to check using a key.

Ex.
doc1:
{
[
{
key:1,
value:100
},
{
key:5,
value:500
}
]
}

Suppose, I want to insert {key: 1, value:200}
First, it should check that key already exist or not. If exist It should change the value of key:1 that is 100 to 200. If not it should append in the array.

Please help.