My use-case:
I want to maintain a list of children-ids on each master. Each child also has a masterId and adds itself to the master in our code using arrayAddUnique.
Now I also want to remove the child-id from the master e.g. when the child is removed or assigned to a different master.
Code:
I am currently adding to an array using SubdocumentAPI via:
Haven’t found a method ‘arrayRemove’ yet, although on this site it says:
Mutating Array Fields
The sub-document API supports a similar set of commands on arrays as on dictionaries. It also adds the ability to push items to the beginning or the end of an array, without having to explicitly check the current length of the array.
…
Deleting an existing array element (reducing the array size by 1) using remove.
Does this ‘remove’ method exist or is it called differently in the Java SDK?
You can only remove an array element by index - e.g. REMOVE("array[2]")
If you want to be able to remove elements by value you need to use a dictionary - for example you could instead model your set by a dictionary where the elements are keys (and just use empty values).
I’ve put the Expression.i( because my ids look a bit more complex e.g. dsrecord::oid2:default:e96876b2e6e711e6b8f3e4ce8f208bf2 so I guess I need to escape special characters.
I wish there will be native support for removing simple strings from a set in the future.
From reading this sourcecode it looks like operations like setRemove under the hood still fetch the whole document.
I would prefer having Couchbase Server handle this internally more efficiently without the extra roundtrip.