Is it possible to do a conditional update based on a query in single request?

To start off below is my doc sample. What i am trying to do is to query the emails array for a match on a tracking number, and see if there is a opened key and its set to true. If it is not set to true i want to set it to true and then increment nbr_of_emails_opened and nbr_of_unique_emails-opened +1, if it is true i only want to update nbr_of_emails-opened +1.

i know i can do this simply with 2 Queries, first one get the sub doc which matches the track_request and based on the info provided execute a N1Ql update to either 1 or 3 values. But i am trying to cut down on Network roundtrip time and hope with enhancement in 6.5 there is a way to do this like in SQL with stored procedures

“_type”: “email_campaign”,
“status”: “Active”,
“start_date”: “04/17/2020”,
“end_date”: “”,
“template_id”: “template::0a2decdd-3acd-4661-9721-1a9ec0d039e6”,
“summary”: “Reflections Update”,
“metrics”: {
“first_email_sent”: “”,
“last_email_send”: “2020-04-17T22:11:52.317Z”,
“nbr_of_emails”: 185,
“nbr_of_bounces”: 1,
“nbr_of_email_opened”: 0,
“nbr_of_attachments_opened”: 0,
“nbr_of_unique_email_opened”: 0,
“nbr_of_unique_attachments_opened”: 0
“tags”: ,
“librarys”: ,
“history”: {
“created_on”: “04/17/2020 13:24:33”,
“created_by”: “1233”,
“updated_on”: “”,
“updated_by”: “”
“emails”: [
“email”: [
“track_request”: “track_request::9189a59f-55e4-4cf2-a692-4e9a80fd3125”,
“tracking_nbr”: “4b6hCNt-6”
“email”: [
“track_request”: “track_request::7832472e-2eae-4bbe-83a7-fd928f7acd9c”,
“tracking_nbr”: “s-Z4t9fwJ6”

UPDATE default AS d
SET  e.opened = true FOR e IN d.emails  WHEN e.tracking_nbr =  "4b6hCNt-6" END,
           d.metrics.nbr_of_email_opened  = d.metrics.nbr_of_email_opened +1 ,
           d.metrics.nbr_of_unique_email_opened =  d.metrics.nbr_of_unique_email_opened + 
                     CASE WHEN  (ANY e IN d.emails SATISFIES e.tracking_nbr =  "4b6hCNt-6" AND (e.opened  IS NOT VALUED OR e.opened = false) END) THEN 1 ELSE 0 END
WHERE  d._type = "email_campaign" AND ANY e IN d.emails SATISFIES e.tracking_nbr =  "4b6hCNt-6" END;

Thanks that works nicely, i actually made it faster by using the KEY. Also you have a minor typo in the code you have TEHN vs THEN. Also will there be a in 6.5 or later something like a real stored procedure or function which would be prcompiled on server and can be called from a N1QL Query ?

6.5 has User Defined functions in DP mode.

SQL Stored procedure is on Road Map. MB-38950