Update array of object if object exist else insert new object

I have document with key collection:31 as following

{
 "userId": 31,
 "collection": [{
 	"id":"1b3e4567-e89b-12d3-a456-4nD66u5T40f0p",
 	"impact": 5,
 	"level": 3,
 	"title": "Souvenir",
 	"mate": "RHIO",
 	"beacon": null
 },
 {
 	"id":"48093399-c258-4ea0-a56a-8e0e8631b6ab",
 	"impact": 1,
 	"level": 3,
 	"title": "Memento",
 	"mate": "RHIO",
 	"beacon": "US"
 },
 {
 	"id":"2ab82eb1-c67f-4858-96ee-1684c1b0e8b6",
 	"impact": 3,
 	"level": 2,
 	"title": "Trophy",
 	"mate": "LEO",
 	"beacon": "AU"
 }]
}

Now I want to add new collection object in the array but if that ID exist then I want to update it otherwise I want to insert the new object into collections array.

Your help will be much appreciated.