Subdocument upsert() fails for array element ("list[1]", etc)

First off, the environment:

Couchbase Server: 4.5.1-2844
PHP: 7.1.1
PHP SDK: 2.2.4

The issue that I’m seeing is that a subdocument upsert() will fail when given an array element path (such as “list[1]”). Assume the following example document:

{“list”: [“Item 1”, “Item 2”]}

This operation will fail:

$bucket->mutateIn(‘testdocument’)->upsert(‘list[1]’, ‘Modified item’)->execute();

The main error code is 73 (LCB_SUBDOC_MULTI_FAILURE), while the path’s error code is 65 (LCB_SUBDOC_PATH_EINVAL).

This seems wrong. If I use replace(), it works. If I upsert(‘some-other-key’, ‘some data’), it works. It seems to only blow up when provided an array element. What is going on here?

because upsert works with dictionaries (JSON objects), if you want to work with arrays, use array* methods of the builder