How to UDF Record Update with Filter in Node.js client?

This code, doesn’t perform the update, returns a null

Node.js code:

var options = { UDF : {module: module, funcname: functionName, args: arguments} , filters : filters}
var scanBackground = dbConnections.aerospike.client.query(ns, set, options );
var queryStream = scanBackground.execute();

Where options is equal to :

Lua code is:

function updateUserId(rec,newUserId)
    rec['userId'] = newUserId

This does not update any records. If I in aql run the following query: select * from CRM.visit where userId = ‘ogf9DjNC’

I get 4 rows.

What am I doing wrong?

Can you see if you can apply this record UDF on a single record? Pick a record which does not yet have a userId and

show indexes
execute SalesFunctions.updateUserId() on CRM.visit where PK = 'ogf9DjNC'
select * from CRM.visit where PK='ogf9DjNC'

Does it work? Do you see the secondary index on userId in CRM.visit?

userId is Secondary Index.

aql> execute SalesFunctions.updateUserId() on CRM.visit where PK = 'ogf9DjNC'

Error: (100) UDF: Execution Error 1 Produces that error.

aql> execute SalesFunctions.updateUserId() on CRM.visit where userId = ‘ogf9DjNC’ Error: “Execute” supports a complete namespace scan or a primary-key operation. Type help for syntax.

So looks like UDF is not very useful when it comes to secondary indexes. It’s either ALL or 1.

Well, you have an error either with registering the UDF or in executing it. Do you have logs turned on for the UDF?

Currently you can do a stream UDF (aggregation) against a secondary index query. Being able to apply a record UDF to a secondary index query is under development.

I will turn on the logging, the aggregation UDF only has copy of the object so update isn’t an option, so applying update on record only works with primary keys. So I think only option I have is to

  1. Get all keys with regular query
  2. Then loop through keys and execute update on each

Is there anyway to do the above within 1 connection , like get keys and then execute update on array of those keys? Or is there a way to isolate records using secondary index and then apply mass update on all those records at the same time?

The record-UDF over secondary index queries is showing up with the next release of the C client. Therefore the clients that make use of the C client will shortly be supporting that functionality (Python, PHP, node.js, etc). You can wait for that feature or make use of a workaround, as you suggested.

Thank you, whats the ETA on next release?

Sorry, I can’t make a promise on the ETA of the client release, other than saying that this feature is ready to go.

All good, thanks for all your hard work.