User defined function returns same result for all rows in a query

I have created a UDF as below

CREATE or replace FUNCTION counts(...) { (
  SELECT raw count(*)
  FROM  mybucket._default.mycollection
  WHERE SEARCH(term,args[0])

and use it in a query

select counts(term)[0] from mybucket._default.mycollection limit 10;

which returns the same value for all 10 rows…

I tried a much simpler function that just return length based on the example in the docs, just to verify it works

CREATE or replace FUNCTION counts(...) { length(args[0]) };

above works i.e. select query return correct length value for each row, whereas changing the function to select syntax

CREATE or replace FUNCTION counts(...) { (select length(args[0]) ) };

returns incorrect results, i.e. same value for all rows, which is the length of term in the first record.

Any hints on how to create UDF with select clause and parameter for use in a select/update query?

Using Couchbase Enterprise Edition 7.0.0 build 5302

Sorry about that!
Logged MB-48954 - more news on monday…

OK - the state of affairs is that the cause is understood, but the fix is potentially more complex than at first envisaged…

It’s fixed in 7.1 and should be able to backport to 7.0.3