Add or Update in a single query

Is it possible (And I would love to get a sample) to have a query that tries to add a document if it not exist and if its already in the database than update some fields in the existing document ?
Currently I try to do insert and if got a result the document already exist I do a second query to update the required fields.
I would like to do it in a single call.



Please take a look at the documentation for the MERGE statement.