SUBDOC operations in PHP

What is the correct syntax if i want to do an upsert on a supdoc in php and also want to create the parents if they dont exist ?

I tried

  $bucket->mutateIn("$myNbr")
            ->counter('hits', 1)
            ->upsert('stats.lastaccess', 'Modified',create_parents=True))
            ->execute();

but that don’t work, also will the create parents work for the counter field and if so whats the syntax for counter to create the field and set initial value as well as increase by 1 if it exists.
i found some docs on sub doc but the syntax seems to be different for PHP.

You should write it like this:

  $bucket->mutateIn("$myNbr")
            ->counter('hits', 1)
            ->upsert('stats.lastaccess', 'Modified', ['createPath' => true]))
            ->execute();

See the docs for all possible options: http://docs.couchbase.com/sdk-api/couchbase-php-client-2.3.3/classes/Couchbase.MutateInBuilder.html#method_upsert

is there a way to upsert a complete json sub doc (array) under a new parent ? I create a new doc which looks like this

{
  "transaction": "5936F5BF67F91",
  "status": "OK",
  "replycoded": "000",
  "pointcode": "243.100.000",
  "ao": "6010",
  "carriername": "AT&T",
  "cat": "WIRELESS",
  "lata": "730",
  "cname": "WIRELESS CALLER"
}

i want now to update the doc with the folowing data under CodeOwner

{
    "region": "WC",
    "status": "AS",
    "ocn": "6006",
    "date_assigned": "2014-09-05"
}

so that my new doc looks like this

{
  "transaction": "5936F5BF67F91",
  "status": "OK",
  "replycoded": "000",
  "pointcode": "243.100.000",
  "ao": "6010",
  "carriername": "AT&T",
  "cat": "WIRELESS",
  "lata": "730",
  "cname": "WIRELESS CALLER",
  "CodeOwner": {
    "region": "WC",
    "status": "AS",
    "ocn": "6006",
    "date_assigned": "2014-09-05"
  }
}

i know i can do it via individual items like

$bucket->mutateIn("$myNbr")
->upsert('CodeOwne.region', 'WC', ['createPath' => true])
->upsert('CodeOwne.status', 'AS', ['createPath' => true])
->upsert('CodeOwne.ocn', '6006', ['createPath' => true])
->upsert('CodeOwne.date_assigned', '2014-09-05', ['createPath' => true])
->execute();

but i am trying to see if there is a way to create the whole thing in one

You can do it like this:

$codeOwner = [
  "region" => "WC",
  "status" => "AS",
  "ocn" => "6006",
  "date_assigned" => "2014-09-05"
];

$bucket->mutateIn("$myNbr")
->upsert('CodeOwner', $codeOwner)
->execute();

Thanks, is there any traffic or speed benefit doing this vs multiple upserts. coding wise there is not much diffrence since i will have to take my mysqlquery result and access the values for both options.

the obvious benefit in traffic, when new parts are smaller than the whole document.