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.
If you structured your data as a map instead of an array (which it seems like you logically are using it as a map, with id is your identifier) then you could use the Sub-document API’s DICT_UPSERT command.